This is a migrated thread and some comments may be shown as answers.

Get list of selected checkboxes of client template column

2 Answers 761 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BitShift
Top achievements
Rank 1
Veteran
BitShift asked on 10 Dec 2020, 07:24 PM

Have a field of a grid with a client template like this.  Includes a "check all " box in the header.

columns.Template(@<text></text>).ClientTemplate("<input type='checkbox' id='gridCheckbox'  onclick='handleClick(this);' value='#= LineItemId #'  #= Selected ? 'checked':'' # class='chkbx' />")
           .HeaderTemplate("<input type='checkbox' id='masterCheckBox' onclick='checkAll(this)'/>").Width(50);

 

I have a button that when clicked needs to grab the value of any checkbox (its value is a number) that is checked in this field,  and put into a list or array. This list should not include the checkbox in the header.  I seen this example but its not quite what im trying to do, but similar idea.  I need a jquery selector to get a list of those checkboxes that are checked and the value attribute put into an array.

2 Answers, 1 is accepted

Sort by
0
BitShift
Top achievements
Rank 1
Veteran
answered on 10 Dec 2020, 07:51 PM
Wait a min, I think I figured out a solution.  I already have jquery methods to handle checking single or all the checkboxes in that field. Within these methods I can just grab the id and store it in the array variable that is scoped to the page.  However I would also have to handle removing any values that are associated with un-checked boxes.
0
BitShift
Top achievements
Rank 1
Veteran
answered on 11 Dec 2020, 06:13 PM

I figured it out

var grid = $("#MyGrid").data("kendoGrid");
// Get selected rows
var sel = $("input:checked", grid.tbody).closest("tr");
// Get data item for each and save LineItemId to array
var items = [];
$.each(sel, function (idx, row) {
    var item = grid.dataItem(row);
    items.push(item.LineItemId);
});
 
alert(items);
Tags
Grid
Asked by
BitShift
Top achievements
Rank 1
Veteran
Answers by
BitShift
Top achievements
Rank 1
Veteran
Share this question
or