GetSelectedRecords in GRID

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();


    }



1 Reply

RS Renjith Singh Rajendran Syncfusion Team July 9, 2021 03:30 AM UTC

Hi Dan, 

Greetings from Syncfusion support. 

We suspect that you are facing difficulties in selecting the rows in Grid. We could see that you have enabled CheckboxOnly property in GridSelectionSettings, but from your shared code, we could not find any Checkbox typed column. So if you are facing problem with selecting rows in grid, then we suggest you to ensure to define Checkbox typed column to overcome this reported issue.  

Please add the below highlighted GridColumn to perform selection in Grid. 

<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 


After adding the above code, you can use the GetSelectedRecords method of Grid(as you have used in your code) to fetch the selected rows and pass it to your service. 

If we have misunderstood your query or if you are still facing difficulties then kindly share with us the following details to proceed further. 

  1. Share a detailed explanation of the problem you are facing.
  2. Share a video demo explaining the scenario or problem you are facing.
  3. Are you facing problem in fetching the selected records using GetSelectedRecords method?
  4. Or are you facing difficulties in passing the fetched records from GetSelectedRecords method to server/service? If so, share the details of problem you are facing.
  5. Share a simple sample which you have tried from your side.
  6. Share your complete grid rendering codes.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith R 


Loader.
Up arrow icon