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.