jqgrid multiselect in Apple and Windows Style – Mehrfachselektion von Tabellenzeilen

16. Juni 2014 - JavaScript

Oleg von Trirand.com hat auf stackoverflow eine Lösung angegeben, bei der man in jqgrid Tabellenzeilen wie unter Windows mit Shift- und Control-Key selektieren kann.
Die daraus entwickelte Lösung ist auch noch zum Apple (Command-key) kompatibel

 

English Summary: Below a solution for  jqgrid multiselect that works with shift-, control- and command key in both windows and apple os style

beforeSelectRow: function (rowid, e) {
var _this = $(this), rows = this.rows,
// get id of the previous selected row
startId = _this.jqGrid('getGridParam', 'selrow'),
startRow, endRow, iStart, iEnd, i, rowidIndex;

if (!e.ctrlKey && !e.shiftKey && !e.metaKey) {
_this.jqGrid('resetSelection');
} else if (startId && e.shiftKey) {
_this.jqGrid('resetSelection');

// get DOM elements of the previous selected and the currect selected rows
startRow = rows.namedItem(startId);
endRow = rows.namedItem(rowid);
if (startRow && endRow) {
// get min and max from the indexes of the previous selected
// and the currect selected rows
iStart = Math.min(startRow.rowIndex, endRow.rowIndex);
rowidIndex = endRow.rowIndex;
iEnd = Math.max(startRow.rowIndex, rowidIndex);
for (i = iStart; i <= iEnd; i++) {
// the row with rowid will be selected by jqGrid, so:
if (i != rowidIndex) {
_this.jqGrid('setSelection', rows[i].id, false);
}
}
}

// clear text selection
if(document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
window.getSelection().removeAllRanges();
}
}
return true;
}