...
@{
List<SortDescriptorModel> SortedColumns = new List<SortDescriptorModel>();
SortedColumns.Add(new SortDescriptorModel() { Field = "CustomerID", Direction = SortDirection.Ascending });
}
<EjsGrid @ref="@grid" AllowSorting="true" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" OnActionBegin="@ActionBeginHandler" RowDataBound="@RowDataBoundHandler">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings>
<GridSortSettings Columns="@SortedColumns"></GridSortSettings>
<GridPageSettings PageCount="2"></GridPageSettings>
<GridColumns>
...
</GridColumns>
</EjsGrid>
@functions{
EjsGrid grid;
List<int?> ids = new List<int?>();
public List<Order>
Orders
{ get; set; }
public void ActionBeginHandler(ActionEventArgs args)
{
if (args.RequestType.ToString() == "Save")
{
var data = JsonConvert.DeserializeObject<Order>(JsonConvert.SerializeObject(args.Data));
ids.Add(data.OrderID);
}
}
public void RowDataBoundHandler(RowDataBoundEventArgs args)
{
if (ids.Contains(JsonConvert.DeserializeObject<Order>(JsonConvert.SerializeObject(args.Data)).OrderID))
{
args.Row.AddClass(new string[] { "green" });
}
} ...
}
<style>
.green {
background-color: lightgreen;
}
</style>
|
...
@{
List<SortDescriptorModel> SortedColumns = new List<SortDescriptorModel>();
SortedColumns.Add(new SortDescriptorModel() { Field = "CustomerID", Direction = SortDirection.Ascending }); //initial sorting
}
<EjsGrid @ref="@grid" AllowSorting="true" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridEvents OnDataBound="DataBoundHandler" OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings>
<GridSortSettings Columns="@SortedColumns"></GridSortSettings>
<GridPageSettings PageCount="2"></GridPageSettings>
<GridColumns>
...
</GridColumns>
</EjsGrid>
@functions{
EjsGrid<Order> Grid;
public static int? Pkey { get; set; }
public bool Initial { get; set; } = true;
...
public void ActionBeginHandler(ActionEventArgs<Order> args)
{
if (args.RequestType.ToString() == "Save")
{
Pkey = args.Data.OrderID; //get primary key value of newly added record
}
}
public async void DataBoundHandler(BeforeDataBoundArgs<Order> args)
{
if (!Initial) {
await Task.Delay(100);
var Idx = await this.Grid.GetRowIndexByPrimaryKey(Convert.ToDouble(Pkey)); //get index value
this.Grid.SelectRow(Convert.ToDouble(Idx)); //select the added row by using index value of the record
}
Initial = false;
}
...
}
|