@using Syncfusion.Blazor.Grids
<Syncfusion.Blazor.Buttons.SfButton @onclick="SetCellValue">SetCellValue</Syncfusion.Blazor.Buttons.SfButton>
<Syncfusion.Blazor.Buttons.SfButton @onclick="UpdateCell">UpdateCell</Syncfusion.Blazor.Buttons.SfButton>
<SfGrid @ref="Grid" ID="Grid" DataSource="@Orders" AllowSorting="true" AllowPaging="true">
<GridPageSettings PageSize="8"></GridPageSettings>
<GridSelectionSettings PersistSelection="true"></GridSelectionSettings>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="50"></GridColumn>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
SfGrid<Order> Grid { get; set; }
public void SetCellValue()
{
Grid.SetCellValue(1001, "CustomerID", "SetCellValue!");
}
private void UpdateCell()
{
Grid.UpdateCell(1, "CustomerID", "UpdateCell!");
}
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2.1 * x,
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
public class Order
{
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
}
|
private void UpdateCell()
{
Grid.UpdateCell(1, "CustomerID", "UpdateCell!");
} |