JQGrid - Multiselect

Multiselect in JQGrid allows only multiple selection or single selection, and shift functionality is not what I expect from shift selection. I also don't like that we need comboboxes with multiselect.

What other solution can I use for the multi selector?

+6
jquery jqgrid multi-select
source share
1 answer

[Oct 2011] . Updated to use API 4.0, fixed shift selection errors, simplified selection cycle. Tested in 4.2.0.


If I like it, you need the right multi selector in jqgrid - where ctrl selects one row at a time, selects several rows and does not clear the selection and selects 1 row - you found it.

First things first : set multiselect: true in the grid definition (I didn't set any other multi selector options)

Next: In gridComplete: function () {} set grid.jqGrid('hideCol', 'cb'); - this hides the checkboxes if you do not want them.

Finally : the main part

 beforeSelectRow: function (rowid, e) { if (!e.ctrlKey && !e.shiftKey) { $("#grid").jqGrid('resetSelection'); } else if (e.shiftKey) { var initialRowSelect = $("#grid").jqGrid('getGridParam', 'selrow'); $("#grid").jqGrid('resetSelection'); var CurrentSelectIndex = $("#grid").jqGrid('getInd', rowid); var InitialSelectIndex = $("#grid").jqGrid('getInd', initialRowSelect); var startID = ""; var endID = ""; if (CurrentSelectIndex > InitialSelectIndex) { startID = initialRowSelect; endID = rowid; } else { startID = rowid; endID = initialRowSelect; } var shouldSelectRow = false; $.each($("#grid").getDataIDs(), function(_, id){ if ((shouldSelectRow = id == startID || shouldSelectRow)){ $("#grid").jqGrid('setSelection', id, false); } return id != endID; }); } return true; } 

The End - Hope That Helps

+26
source share

All Articles