SHift单击jqgrid multiselect缺少最后一行

jef*_*ind 4 javascript jquery jqgrid shift multi-select

我从这篇文章中采用了这个代码并制作了这个小提琴.尝试单击第一行,然后按住Shift键单击最后一行.如果您注意到此代码执行得很好,除最后一行外,您单击的行不会被选中.我一直在摸着这个.任何人都可以帮我改变代码,以便multiselect也选择最后一行吗?

谢谢!

Mic*_*din 6

尝试替换这个:if ((shouldSelectRow = id == startID || shouldSelectRow)) {用这个:

if ((shouldSelectRow = id == startID || shouldSelectRow) && (id != rowid)){
Run Code Online (Sandbox Code Playgroud)


Ole*_*leg 5

我同意Michael Gendin你不应该选择id等于的行rowid.这是你的主要错误.不过我会重写演示的大部分代码,使用行的DOM元素的rowIndex而不是枚举网格的所有行.此外,在您当前的代码中选择IE中的文本是不舒服的,所以我建议删除它.您在这里找到的修改过的演示我使用了以下beforeSelectRow回调代码:

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) {
        $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;
}
Run Code Online (Sandbox Code Playgroud)