Dear Support,
please see code below. i have enabled
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" CheckboxOnly="true" PersistSelection="true">.
a)I need to get the Selected Objects e.g. Id and UserName,
and send it to the service/server.
b)I need to get the selected Objects Id s in a List{Int}, and send that list to the server for further processing.
can you please send us a code snipset for the above two scenarios that will work, as we did not manage to achieve that.
thank you
@{
List<Syncfusion.Blazor.Navigations.ItemModel> Toolbaritems = new List<Syncfusion.Blazor.Navigations.ItemModel>();
Toolbaritems.Add(new Syncfusion.Blazor.Navigations.ItemModel() { Text = "Add", Id = "add", TooltipText = "Add", PrefixIcon = "fa fa-plus" });
Toolbaritems.Add(new Syncfusion.Blazor.Navigations.ItemModel() { Text = "Test Sms Gateway", Id = "testsmsgateway", TooltipText = "Test Sms Gateway", PrefixIcon = "fas fa-sms" });
//Toolbaritems.Add(new Syncfusion.Blazor.Navigations.ItemModel() { Text = "Delete", Id = "delete", TooltipText = "Delete Record", PrefixIcon = "delete" });
}
<SfGrid @ref="GridnameSettingSmsGateways" Toolbar="Toolbaritems" DataSource="@SettingSmsGatewayObjects" AllowPaging="true" AllowSorting="true" AllowFiltering="true" Width="100%">
<GridEvents OnToolbarClick="ToolbarClickHandler" TValue="SettingSmsGateway"></GridEvents>
<GridEvents RowSelected="RowSelectHandler" RowDeselected="RowDeselectHandler" TValue="SettingSmsGateway"></GridEvents>
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" CheckboxOnly="true" PersistSelection="true"></GridSelectionSettings>
<GridColumn Field=@nameof(MyApp.Model.SettingSmsGateway.Id) HeaderText="Id" TextAlign="TextAlign.Left" IsPrimaryKey="true" Width="120"></GridColumn>
<GridColumn Field=@nameof(MyApp.Model.SettingSmsGateway.Username) HeaderText="Username" TextAlign="TextAlign.Left" IsIdentity="true" Width="120"></GridColumn>
</SfGrid>
@code {
SfGrid<SettingSmsGateway> GridnameSettingSmsGateways;
public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id== "add")
{
settingsmsgatewayModel = new MyApp.Model.SettingSmsGateway();
this.IsVisible = true;
}
if (args.Item.Id == "testsmsgateway")
{
//
}
}
public async void RowSelectHandler(RowSelectEventArgs<SettingSmsGateway> args)
{
//all the selected records are getting properly
var SelectedRecords = await GridnameSettingSmsGateways.GetSelectedRecords();
var RowCountSelected = SelectedRecords.Count();
var temp = await GridnameSettingSmsGateways.GetSelectedRecords(); // store the selected records in a variable here
Console.Write("#### selected items: "); //show the selected records count here
Console.WriteLine(temp.Count); // get the selected records count here
}
public async void RowDeselectHandler(RowDeselectEventArgs<SettingSmsGateway> args)
{
//RowDeselected – it will show the remaining selected records while deselecting(deselected one in not countable)
var SelectedRecords = await GridnameSettingSmsGateways.GetSelectedRecords();
var RowCountSelected = SelectedRecords.Count();
var temp = await GridnameSettingSmsGateways.GetSelectedRecords(); // store the selected records in a variable here
Console.Write("#### selected items: "); //show the selected records count here
Console.WriteLine(temp.Count); // get the selected records count here
}
public async Task SmsSend()
{
settingsmsgatewayService.SmsSendTest();
StateHasChanged();
}
<SfGrid @ref="GridnameSettingSmsGateways" ...>
...
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" CheckboxOnly="true" PersistSelection="true"></GridSelectionSettings>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox"></GridColumn>
<GridColumn Field=@nameof(SettingSmsGateway.Id) HeaderText="Id" TextAlign="TextAlign.Left" IsPrimaryKey="true" Width="120"></GridColumn>
...
</GridColumns>
</SfGrid
|