0

I have a jqgrid. on my grid I used the script tp enable shift Key to select a series of selections. I used this answer

of Oleg. I used it as this way:

     beforeSelectRow: function (rowid, e) {

                     return shiftSelect(rowid, e);
                    },



function shiftSelect(rowid, e) {
    console.log(rowid);
    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;  
}

The issue that I have is: when I click on a row I get this error: Uncaught TypeError: Cannot read property 'frozenColumns' of undefined

But when I put the function inside the beforeSelectRow, everything is working fine. Any idea?

Community
  • 1
  • 1
user3833823
  • 173
  • 1
  • 2
  • 12

1 Answers1

0

Here is the answer:

beforeSelectRow: shiftSelect,

var shiftSelect = 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;  

    };
user3833823
  • 173
  • 1
  • 2
  • 12