jQGrid Batch Select Handler

After implementing the standard jQGrid I always do for a new feature in our system at work, a user enquired whether I could make it possible to add functionality so select one row, then shift-clicking on another x rows down, would select those and all rows inbetween.

In the $gridOpts array:

'beforeSelectRow' => new Zend_Json_Expr('Path.To.Javascript.File.Main.multiSelectHandler'),

In the js:

multiSelectHandler: function(rowid, e) {
if (e.shiftKey) {
var initialRowSelect = $("#list").jqGrid('getGridParam', 'selarrrow')[0];
$("#list").setSelection(initialRowSelect, false);

var CurrentSelectIndex = $("#list").getInd(rowid, false);
var InitialSelectIndex = $("#list").getInd(initialRowSelect, false);
var startID = "";
var endID = "";
if (CurrentSelectIndex > InitialSelectIndex) {
startID = initialRowSelect;
endID = rowid;
else {
startID = rowid;
endID = initialRowSelect;

var AllRows = $("#list").getDataIDs();
var SelectRow = false;
for (var i = 0; i < AllRows.length; i++) {
if (SelectRow == true && AllRows[i] != endID) $("#list").setSelection(AllRows[i], false);
else if (AllRows[i] == startID) SelectRow = true;
else if (AllRows[i] == endID) SelectRow = false;
return true;


Leave a Reply

Your email address will not be published. Required fields are marked *