How to reset the selected rows and select all rows on external button click? i am trying to resetSelection() but not working ...
jQuery("selectAll").click(function(){
jQuery('.cbox').trigger('click');
});
jQuery("clear").click(function(){
var grid = $("#list10");
grid.resetSelection();
$('#cb_my_grid').click();
var ids = grid.getDataIDs();
for (var i=0, il=ids.length; i < il; i++ )
grid.setSelection(ids[i], false);
});
How to reset the selected rows and select all rows on external button click? i am trying to resetSelection() but not working ...
jQuery("selectAll").click(function(){
jQuery('.cbox').trigger('click');
});
jQuery("clear").click(function(){
var grid = $("#list10");
grid.resetSelection();
$('#cb_my_grid').click();
var ids = grid.getDataIDs();
for (var i=0, il=ids.length; i < il; i++ )
grid.setSelection(ids[i], false);
});
Share
Improve this question
edited Jul 23, 2019 at 6:47
IdontCareAboutReputationPoints
1,76423 silver badges26 bronze badges
asked Aug 26, 2010 at 0:44
PaulPaul
791 gold badge3 silver badges12 bronze badges
3
- You should post the code example which not work. – Oleg Commented Aug 26, 2010 at 1:37
- jQuery("selectAll").click(function(){ jQuery('.cbox').trigger('click'); }); jQuery("clear").click(function(){ var grid = $("#list10"); grid.resetSelection(); $('#cb_my_grid').click(); var ids = grid.getDataIDs(); for (var i=0, il=ids.length; i < il; i++ ) grid.setSelection(ids[i], false); }); – Paul Commented Aug 26, 2010 at 1:53
- may be this link help cbabhusal.wordpress.com/2014/09/15/… – Shiva Commented Aug 18, 2015 at 2:41
2 Answers
Reset to default 13The main reason why your code is not work is some syntax errors or wrong usage of jQuery selectors.
You don't post your HTML code, so I suppose it look like following
<input id="selectAll" type="button" value="Select All" />
<input id="clear" type="button" value="Clear Selection" />
<table id="list10"></table>
<div id="pager"></div>
The corresponding JavaSript code should be like following:
var grid = $("#list10");
$("#selectAll").click(function(){
grid.jqGrid('resetSelection');
var ids = grid.getDataIDs();
for (var i=0, il=ids.length; i < il; i++) {
grid.jqGrid('setSelection',ids[i], true);
}
});
$("#clear").click(function(){
grid.jqGrid('resetSelection');
});
A working example you can see under the Link .
For those who are still encountering this here is a solution the works for me:
//call resetSelection here
$('#cb_grid_id')
.attr('checked','checked')
.trigger('click')
.attr('checked','checked');