diff options
author | Michael Leibman <michael.leibman@gmail.com> | 2013-08-10 10:08:19 -0700 |
---|---|---|
committer | Michael Leibman <michael.leibman@gmail.com> | 2013-08-10 10:08:19 -0700 |
commit | 4efc3a2b83af71e5a91b527fe91ac6f79419bbff (patch) | |
tree | a5ff26e749ac969d10a14caa89c986ce4523e458 | |
parent | b96dea6840d2da1e68728bbf649279946f7ce467 (diff) | |
download | SlickGrid-4efc3a2b83af71e5a91b527fe91ac6f79419bbff.zip SlickGrid-4efc3a2b83af71e5a91b527fe91ac6f79419bbff.tar.gz SlickGrid-4efc3a2b83af71e5a91b527fe91ac6f79419bbff.tar.bz2 |
Add PgUp/PgDown handling.
-rw-r--r-- | examples/example-colspan.html | 2 | ||||
-rw-r--r-- | slick.grid.js | 84 |
2 files changed, 70 insertions, 16 deletions
diff --git a/examples/example-colspan.html b/examples/example-colspan.html index 8f5fbe4..2448a84 100644 --- a/examples/example-colspan.html +++ b/examples/example-colspan.html @@ -47,7 +47,7 @@ $(function () { var data = []; - for (var i = 0; i < 10; i++) { + for (var i = 0; i < 500; i++) { data[i] = { title: "Task " + i, duration: "5 days", diff --git a/slick.grid.js b/slick.grid.js index d40e546..003533d 100644 --- a/slick.grid.js +++ b/slick.grid.js @@ -299,6 +299,7 @@ if (typeof Slick === "undefined") { $container
.bind("resize.slickgrid", resizeCanvas);
$viewport
+ .bind("click", handleClick)
.bind("scroll", handleScroll);
$headerScroller
.bind("contextmenu", handleHeaderContextMenu)
@@ -1258,6 +1259,10 @@ if (typeof Slick === "undefined") { }
}
+ function getDataLengthIncludingAddNew() {
+ return getDataLength() + (options.enableAddRow ? 1 : 0);
+ }
+
function getDataItem(i) {
if (data.getItem) {
return data.getItem(i);
@@ -1565,7 +1570,7 @@ if (typeof Slick === "undefined") { function resizeCanvas() {
if (!initialized) { return; }
if (options.autoHeight) {
- viewportH = options.rowHeight * (getDataLength() + (options.enableAddRow ? 1 : 0));
+ viewportH = options.rowHeight * getDataLengthIncludingAddNew();
} else {
viewportH = getViewportHeight();
}
@@ -1588,8 +1593,7 @@ if (typeof Slick === "undefined") { function updateRowCount() {
var dataLength = getDataLength();
if (!initialized) { return; }
- numberOfRows = dataLength +
- (options.enableAddRow ? 1 : 0) +
+ numberOfRows = getDataLengthIncludingAddNew() +
(options.leaveSpaceForNewRows ? numVisibleRows - 1 : 0);
var oldViewportHasVScroll = viewportHasVScroll;
@@ -1598,7 +1602,7 @@ if (typeof Slick === "undefined") { // remove the rows that are now outside of the data range
// this helps avoid redundant calls to .removeRow() when the size of the data decreased by thousands of rows
- var l = options.enableAddRow ? dataLength : dataLength - 1;
+ var l = getDataLengthIncludingAddNew() - 1;
for (var i in rowsCache) {
if (i >= l) {
removeRowFromCache(i);
@@ -1684,7 +1688,7 @@ if (typeof Slick === "undefined") { }
range.top = Math.max(0, range.top);
- range.bottom = Math.min(options.enableAddRow ? getDataLength() : getDataLength() - 1, range.bottom);
+ range.bottom = Math.min(getDataLengthIncludingAddNew() - 1, range.bottom);
range.leftPx -= viewportW;
range.rightPx += viewportW;
@@ -1919,7 +1923,7 @@ if (typeof Slick === "undefined") { renderRows(rendered);
postProcessFromRow = visible.top;
- postProcessToRow = Math.min(options.enableAddRow ? getDataLength() : getDataLength() - 1, visible.bottom);
+ postProcessToRow = Math.min(getDataLengthIncludingAddNew() - 1, visible.bottom);
startPostProcessing();
lastRenderedScrollTop = scrollTop;
@@ -2164,6 +2168,12 @@ if (typeof Slick === "undefined") { return; // no editing mode to cancel, allow bubbling and default processing (exit without cancelling the event)
}
cancelEditAndSetFocus();
+ } else if (e.which == 34) {
+ scrollPageDown();
+ handled = true;
+ } else if (e.which == 33) {
+ scrollPageUp();
+ handled = true;
} else if (e.which == 37) {
handled = navigateLeft();
} else if (e.which == 39) {
@@ -2233,7 +2243,7 @@ if (typeof Slick === "undefined") { if ((activeCell != cell.cell || activeRow != cell.row) && canCellBeActive(cell.row, cell.cell)) {
if (!getEditorLock().isActive() || getEditorLock().commitCurrentEdit()) {
scrollRowIntoView(cell.row, false);
- setActiveCellInternal(getCellNode(cell.row, cell.cell), (cell.row === getDataLength()) || options.autoEdit);
+ setActiveCellInternal(getCellNode(cell.row, cell.cell));
}
}
}
@@ -2416,7 +2426,7 @@ if (typeof Slick === "undefined") { }
}
- function setActiveCellInternal(newCell, editMode) {
+ function setActiveCellInternal(newCell, opt_editMode) {
if (activeCellNode !== null) {
makeActiveCellNormal();
$(activeCellNode).removeClass("active");
@@ -2432,10 +2442,14 @@ if (typeof Slick === "undefined") { activeRow = getRowFromNode(activeCellNode.parentNode);
activeCell = activePosX = getCellFromNode(activeCellNode);
+ if (opt_editMode == null) {
+ opt_editMode = (activeRow == getDataLength()) || options.autoEdit;
+ }
+
$(activeCellNode).addClass("active");
$(rowsCache[activeRow].rowNode).addClass("active");
- if (options.editable && editMode && isCellPotentiallyEditable(activeRow, activeCell)) {
+ if (options.editable && opt_editMode && isCellPotentiallyEditable(activeRow, activeCell)) {
clearTimeout(h_editorLoader);
if (options.asyncEditorLoading) {
@@ -2693,6 +2707,46 @@ if (typeof Slick === "undefined") { render();
}
+ function scrollPage(dir) {
+ var deltaRows = dir * numVisibleRows;
+ scrollTo((getRowFromPosition(scrollTop) + deltaRows) * options.rowHeight);
+ render();
+
+ if (options.enableCellNavigation && activeRow != null) {
+ var row = activeRow + deltaRows;
+ if (row >= getDataLengthIncludingAddNew()) {
+ row = getDataLengthIncludingAddNew() - 1;
+ }
+ if (row < 0) {
+ row = 0;
+ }
+
+ var cell = 0, prevCell = null;
+ var prevActivePosX = activePosX;
+ while (cell <= activePosX) {
+ if (canCellBeActive(row, cell)) {
+ prevCell = cell;
+ }
+ cell += getColspan(row, cell);
+ }
+
+ if (prevCell !== null) {
+ setActiveCellInternal(getCellNode(row, prevCell));
+ activePosX = prevActivePosX;
+ } else {
+ resetActiveCell();
+ }
+ }
+ }
+
+ function scrollPageDown() {
+ scrollPage(1);
+ }
+
+ function scrollPageUp() {
+ scrollPage(-1);
+ }
+
function getColspan(row, cell) {
var metadata = data.getItemMetadata && data.getItemMetadata(row);
if (!metadata || !metadata.columns) {
@@ -2784,7 +2838,7 @@ if (typeof Slick === "undefined") { function gotoDown(row, cell, posX) {
var prevCell;
while (true) {
- if (++row >= getDataLength() + (options.enableAddRow ? 1 : 0)) {
+ if (++row >= getDataLengthIncludingAddNew()) {
return null;
}
@@ -2845,7 +2899,7 @@ if (typeof Slick === "undefined") { }
var firstFocusableCell = null;
- while (++row < getDataLength() + (options.enableAddRow ? 1 : 0)) {
+ while (++row < getDataLengthIncludingAddNew()) {
firstFocusableCell = findFirstFocusableCell(row);
if (firstFocusableCell !== null) {
return {
@@ -2860,7 +2914,7 @@ if (typeof Slick === "undefined") { function gotoPrev(row, cell, posX) {
if (row == null && cell == null) {
- row = getDataLength() + (options.enableAddRow ? 1 : 0) - 1;
+ row = getDataLengthIncludingAddNew() - 1;
cell = posX = columns.length - 1;
if (canCellBeActive(row, cell)) {
return {
@@ -2960,11 +3014,11 @@ if (typeof Slick === "undefined") { if (pos) {
var isAddNewRow = (pos.row == getDataLength());
scrollCellIntoView(pos.row, pos.cell, !isAddNewRow);
- setActiveCellInternal(getCellNode(pos.row, pos.cell), isAddNewRow || options.autoEdit);
+ setActiveCellInternal(getCellNode(pos.row, pos.cell));
activePosX = pos.posX;
return true;
} else {
- setActiveCellInternal(getCellNode(activeRow, activeCell), (activeRow == getDataLength()) || options.autoEdit);
+ setActiveCellInternal(getCellNode(activeRow, activeCell));
return false;
}
}
@@ -2992,7 +3046,7 @@ if (typeof Slick === "undefined") { }
function canCellBeActive(row, cell) {
- if (!options.enableCellNavigation || row >= getDataLength() + (options.enableAddRow ? 1 : 0) ||
+ if (!options.enableCellNavigation || row >= getDataLengthIncludingAddNew() ||
row < 0 || cell >= columns.length || cell < 0) {
return false;
}
|