Hi team,
I have just seen this in another platform thread. Is there is a way to do this in blazor?
|
<SfTextBox @bind-Value="@Text"></SfTextBox>
<SfButton OnClick="Clicked" Content="Update Selected"></SfButton>
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" ValidationRules="@(new ValidationRules { Required = true })" Type="ColumnType.Number" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" ValidationRules="@(new ValidationRules{ Required=true})" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public string Text { get; set; }
public SfGrid<Order> Grid { get; set; }
public async Task Clicked()
{
var getSelected = await Grid.GetSelectedRecordsAsync();
foreach (var sel in getSelected)
{
var index = await Grid.GetRowIndexByPrimaryKeyAsync(sel.OrderID);
await Grid.UpdateCellAsync(index, "ShipCountry", Text);
}
}
|
Thanks Vignesh for the immediate response.
btw, another questions
1) Is there is a way to get the index without the ID?
var index = await Grid.GetRowIndexByPrimaryKeyAsync(sel.OrderID);
My Id is auto generated from EFCore after batchsaving. and Newly added lineitem has 0 yet ID.
2) How can I get the all of the lineitems without selecting them all?
var getSelected = await Grid.GetSelectedRecordsAsync();
Warm regards,
Tyrone
|
public async Task Clicked()
{
var getSelected = await Grid.GetCurrentViewRecordsAsync();
foreach (var sel in getSelected)
{
var index = getSelected.IndexOf(sel);
await Grid.UpdateCellAsync(index, "ShipCountry", Text);
}
}
|
Thanks Vignesh.
By the way, is there is a way to get the cell value for each row in Grid.GetCurrentViewRecordsAsync();
I'm planning to use it to get the total (ex. totalAmount) since reactive aggregate is not yet available in batchmode..
Warm Regards,
Tyrone
|
public async Task Clicked()
{
var getSelected = await Grid.GetCurrentViewRecordsAsync();
var total = getSelected[0];
var val = total.CustomerID;
foreach (var sel in getSelected)
{
var index = getSelected.IndexOf(sel);
await Grid.UpdateCellAsync(index, "ShipCountry", Text);
}
}
|
|
|