Loop through rows in a grid

I have a grid with three columns (id, name, checkbox). Now I want to loop through all rows in the grid and where checkbox is checked I want to insert a record into a table with data from the grid.
What would be the best way to do it and does anyone know of samples?

If the checkbox is bound to a property you can filter the array bound to grid data to get only "checked" items like this: yourArray.filter(i => i.yourPropertyBoundToCheckBox). You can pass this (filtered) array to a custom server method and perform desired operation.

How do I know if a checkbox is bound to a property? I added the checkbox through the template to a column in the DataGrid. The checkbox has no connection to a column in a table if it means anything. What I want to happen on the page is when I click on the button I have added to the page I want an event to fire which calls a custom server method to perform the loop and insert.
And one more: Is it possible to add a checkbox in the header of the table to perform select all on the checkbox in the table?

You need to bind it to a property otherwise you will not be able to check the value. Placing CheckBox in DataGrid column header is not supported.

Can you show me a code sample for the array. I cannot figure it out.

Here is an example:

This is not helping me.
What I believe I must do is:

  1. Create custom method.
  2. Invoke it with a button (click event).
  3. Loop through all selected rows.

And here is the thing:

  1. I dont know how to loop through all rows in a grid in Radzen and get data from a column to add as a parameter to insert into function.
  2. I dont know how to use this filter function you are showing me.
  3. I dont know where I can find help and examples and that is why I have to ask you.

This is my custom method in the ServerMethodsController
public string SaveData()
{
this.grid0.data.filter(i => i.checked)
{
//Loop through all rows and fetch data from columns to insert into db.

        })

        return "Save = OK";
    }

Please help me out here so I can go on with this work.

You do not need to loop all the grid rows, you just need the checked. Here is how to get checked rows:

this.grid0.data.filter(i => i.checked)

You have now array of only needed objects and you can use them to send data to your custom server method. Let's say for example you have the following custom custom server method:

[HttpPost]
public IActionResult DoSomething([FromBody] int[] selectedIds)
{
    return new NoContentResult();
}

Now to pass an array with Ids from checked items you need to following instead [1,2,3]:

this.grid0.data.filter(i => i.checked).map(i => i.Id)

I still dont get it.

  1. Where do I put this line: this.grid0.data.filter(i => i.checked).map(i => i.id)
  2. How do I loop through the result of checked rows to insert into db?

this.grid0.data - are all grid rows
this.grid0.data.filter(i => i.checked) - are only checked grid rows
this.grid0.data.filter(i => i.checked).map(i => i.Id) - get the ids of all checked grid rows and pass it to your custom server method.

I get this. But what I have hard time to understand is how I can have access to the Id's in my custom server method. In the server method I have int[] SelectedID. Where do I put this code you are showing me. Is it in the server method or somewhere else?
I would love to see a final example where a custom method saves ids to db.

I'm reporting the code from one of my previous reply:
https://forum.radzen.com/uploads/default/original/2X/2/2f5468ed7ffdd0ca5feddafcb780974baf0c6909.png

When you execute your method with this.grid0.data.filter(i => i.checked).map(i => i.Id) as argument on the Angular side you will have int[] SelectedID populated on the .NET Core side.