In a KendoUI grid with a selection set to "multiple", how do I invert a current selection?
2
I came up with the following solution:
var $grid = $("#grid").data("kendoGrid"); var $selectedRows = $grid.select(); $grid.refresh(); // clear existing selection var selecred_uid = _.map($selectedRows, 'attributes["data-uid"].value'); // using lodash map var $allRows = $grid.items(); $.each($allRows, function (i, row) { var $row = $(row); var uid = $row[0].attributes["data-uid"].value; if (!selecred_uid.includes(uid)) { $grid.select("tr[data-uid='" + uid + "']"); } });
I replaced my initial with @DontVoteMeDown 's much better solution
You can do it in a simpler way:
const $grid = $("#grid").data("kendoGrid"); const $notSelected = $grid.tbody.find('> tr:not(.k-selected)'); $grid.clearSelection(); $grid.select($notSelected);
Dojo
Although it won’t works for paged grids. I think it will need a more complex code for that. But for not paged grid its ok.
Click here to cancel reply.
2
Answers
I came up with the following solution:
I replaced my initial with @DontVoteMeDown 's much better solution
You can do it in a simpler way:
Dojo
Although it won’t works for paged grids. I think it will need a more complex code for that. But for not paged grid its ok.