-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Backiaraj/Grid
Updated the sample
- Loading branch information
Showing
6 changed files
with
405 additions
and
100 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
PreventQueryGeneration/Grid_PreventQueryGeneration/Pages/DataGridFeatures.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
@page "/datagrid-features" | ||
|
||
@using System.ComponentModel.DataAnnotations; | ||
@using Syncfusion.Blazor | ||
@using Syncfusion.Blazor.Data | ||
@using Syncfusion.Blazor.Buttons | ||
@using Syncfusion.Blazor.Grids | ||
@using Syncfusion.Blazor.DropDowns | ||
@using Newtonsoft.Json | ||
|
||
|
||
<SfGrid ID="Grid" @ref="Grid" Query="@currentQuery" TValue="Book" Toolbar="@ToolbarItems" Height="100%" AllowPaging="true" AllowSorting="true" AllowFiltering="true"> | ||
<GridPageSettings PageSize="10" PageSizes="true"></GridPageSettings> | ||
<SfDataManager Url="http://localhost:64956/odata/books" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> | ||
<GridEvents TValue="Book" OnActionBegin="OnActionBegin"/> | ||
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Normal"></GridEditSettings> | ||
<GridColumns> | ||
<GridColumn Field=@nameof(Book.Id) IsPrimaryKey="true" Width="150"></GridColumn> | ||
<GridForeignColumn TValue="Customer" Field=@nameof(Book.CustomerId) AllowFiltering="true" ForeignKeyValue="Name" ForeignKeyField="Id" HeaderText="Name" Width="100" > | ||
<SfDataManager Url="http://localhost:64956/odata/customers" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> | ||
</GridForeignColumn> | ||
<GridColumn Field=@nameof(Book.CreditLimit) Width="200" EditType="EditType.NumericEdit"></GridColumn> | ||
<GridColumn Field=@nameof(Book.Active) Width="200" EditType="EditType.BooleanEdit"></GridColumn> | ||
</GridColumns> | ||
</SfGrid> | ||
|
||
<style> | ||
.e-grid .e-gridcontent .e-rowcell.highlight { | ||
color: red; | ||
font-weight: bolder; | ||
} | ||
</style> | ||
|
||
@code{ | ||
SfGrid<Book> Grid { get; set; } | ||
|
||
|
||
|
||
private Query currentQuery = new Query(); | ||
public List<string> ToolbarItems = new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search" }; | ||
|
||
private void OnActionBegin(Syncfusion.Blazor.Grids.ActionEventArgs<Book> args) | ||
{ | ||
|
||
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering) | ||
{ | ||
|
||
if (String.Equals(args.CurrentFilteringColumn, nameof(Book.CustomerId), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
args.PreventFilterQuery = true; | ||
currentQuery = new Query().Where("Customer/Name", args.CurrentFilterObject.Operator.ToString().ToLower(), args.CurrentFilterObject.Value, true, true); | ||
} | ||
} | ||
} | ||
|
||
|
||
public class Book | ||
{ | ||
[Key] | ||
public Guid Id { get; set; } | ||
public Guid CustomerId { get; set; } | ||
public Guid CustomerId1 { get; set; } | ||
public virtual Customer Customer { get; set; } | ||
public int CreditLimit { get; set; } | ||
public bool Active { get; set; } | ||
public bool IsDeleted { get; set; } | ||
} | ||
|
||
public class Customer | ||
{ | ||
[Key] | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
|
||
[JsonIgnore] | ||
public List<Book> CustomerBooks { get; set; } | ||
|
||
} | ||
} |
123 changes: 68 additions & 55 deletions
123
PreventQueryGeneration/Grid_PreventQueryGeneration/Pages/Index.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,75 @@ | ||
@page "/" | ||
|
||
@using System.ComponentModel.DataAnnotations; | ||
@using Syncfusion.Blazor | ||
@using Syncfusion.Blazor.Data | ||
@using Syncfusion.Blazor.Grids | ||
@using Syncfusion.Blazor.DropDowns | ||
@using Newtonsoft.Json | ||
|
||
<SfGrid ID="Grid" @ref="Grid" Query="@currentQuery" TValue="Book" Toolbar="@ToolbarItems" Height="100%" AllowPaging="true" AllowSorting="true" AllowFiltering="true"> | ||
<GridPageSettings PageSize="10" PageSizes="true"></GridPageSettings> | ||
<SfDataManager Url="http://localhost:64956/odata/books" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> | ||
<GridEvents TValue="Book" OnActionBegin="OnActionBegin" /> | ||
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Normal"></GridEditSettings> | ||
<GridColumns> | ||
<GridColumn Field=@nameof(Book.Id) IsPrimaryKey="true" Width="150"></GridColumn> | ||
<GridForeignColumn TValue="Customer" Field=@nameof(Book.CustomerId) AllowFiltering="true" ForeignKeyValue="Name" ForeignKeyField="Id" HeaderText="Name" Width="100"> | ||
<SfDataManager Url="http://localhost:64956/odata/customers" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> | ||
</GridForeignColumn> | ||
<GridColumn Field=@nameof(Book.CreditLimit) Width="200" EditType="EditType.NumericEdit"></GridColumn> | ||
<GridColumn Field=@nameof(Book.Active) Width="200" EditType="EditType.BooleanEdit"></GridColumn> | ||
</GridColumns> | ||
</SfGrid> | ||
|
||
@code { | ||
SfGrid<Book> Grid { get; set; } | ||
private Query currentQuery = new Query(); | ||
public List<string> ToolbarItems = new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search" }; | ||
|
||
private void OnActionBegin(Syncfusion.Blazor.Grids.ActionEventArgs<Book> args) | ||
{ | ||
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering) | ||
{ | ||
if (String.Equals(args.CurrentFilteringColumn, nameof(Book.CustomerId), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
args.PreventFilterQuery = true; | ||
currentQuery = new Query().Where("Customer/Name", args.CurrentFilterObject.Operator.ToString().ToLower(), args.CurrentFilterObject.Value, true, true); | ||
} | ||
} | ||
<span class="pageheader">Selected Controls</span> | ||
<br /> | ||
<p class="pagecontent">The following Syncfusion Blazor components can be set up in an application for you with the Syncfusion Blazor Template Studio. A fast, easy start with Syncfusion Blazor components lets you concentrate on the important part: learning.</p> | ||
<div class="controlregion"> | ||
|
||
<h5 class="productheader"> Grids</h5> | ||
<ul class="ulstyle"> | ||
<li class="list"> | ||
<NavLink class="nav-link" href="datagrid-features"> | ||
<span class="syncfusion-blazor-index-icons syncfusion-blazor-icon-datagrid" aria-hidden="true"></span>DataGrid | ||
</NavLink> | ||
</li> | ||
|
||
</ul> | ||
|
||
</div> | ||
<style> | ||
.ulstyle { | ||
margin-top: 10px; | ||
margin-bottom: 20px; | ||
display: inline-block; | ||
list-style-type: none !important; | ||
padding-left: 0px !important; | ||
} | ||
.controlregion { | ||
margin-top: 50px; | ||
} | ||
.pagecontent { | ||
font-family: sans-serif !important; | ||
font-size: 16px; | ||
color: #333333; | ||
letter-spacing: 0.34px; | ||
line-height: 24px; | ||
margin-top: 10px; | ||
} | ||
.list { | ||
float: left; | ||
line-height: 40px; | ||
min-width: 280px; | ||
font-family: sans-serif !important; | ||
font-size: 19px; | ||
color: #0073DC; | ||
} | ||
.syncfusion-blazor-index-icons { | ||
font-family: "sbicons"; | ||
color: #0073DC !important; | ||
font-style: normal; | ||
font-weight: normal; | ||
font-variant: normal; | ||
text-transform: none; | ||
padding-right: 13px; | ||
font-size: 18px; | ||
} | ||
public class Book | ||
{ | ||
[Key] | ||
public Guid Id { get; set; } | ||
public Guid CustomerId { get; set; } | ||
public Guid CustomerId1 { get; set; } | ||
public virtual Customer Customer { get; set; } | ||
public int CreditLimit { get; set; } | ||
public bool Active { get; set; } | ||
public bool IsDeleted { get; set; } | ||
.productheader { | ||
font-family: sans-serif !important; | ||
font-size: 19px !important; | ||
color: #333333 !important; | ||
letter-spacing: 0.41px ; | ||
} | ||
public class Customer | ||
{ | ||
[Key] | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
[JsonIgnore] | ||
public List<Book> CustomerBooks { get; set; } | ||
.pageheader { | ||
font-family: sans-serif !important; | ||
font-size: 24px !important; | ||
color: #333333 ; | ||
font-weight: bold !important; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.