Three questions:
If you iterate grid.dataSource.view() you will find only those elements that are in the current page of the grid. If you want to iterate through all elements of the table, you might use grid.dataSource.data() instead.
Iterating you don't need to select a row, since you already have the information in your function. Example, if you do:
$.each(grid.dataSource.view(), function(idx, elem) {
console.log("item with index " + idx + " is ", elem);
})
then elem is the item on row idx.
Last but not least, when you iterate in an array starting from the beginning, you cannot remove elements since there are two consecutive elements that you want to remove, you will remove the first, then increment the counter for proceeding with the next but then the second is actually now in the position of the first so it will be skipped.
Example: If you have the following code:
var array = [3, 2, 1, 5, 6, 4];
console.log("before", array);
$.each(array, function(idx, elem) {
if (elem >= 5) {
array.splice(idx, 1);
}
});
console.log("after", array);
it will display:
before [3, 2, 1, 5, 6, 4]
after [3, 2, 1, 6, 4]
element with value 6 was not removed!!!
You should do, instead, start from the end:
var array = [3, 2, 1, 5, 6, 4];
console.log("before", array);
var len = array.length;
while (len--) {
if (array[len] >= 5) {
array.splice(len, 1);
}
}
console.log("after", array);
getting as result:
before [3, 2, 1, 5, 6, 4]
after [3, 2, 1, 4]
So, your code should be:
var array = grid.dataSource.data();
var len = array.length;
while (len--) {
if (...) { // the condition for checking if the item has the checkbox ticked
grid.dataSource.remove(array[len]);
}
}