Skip to content

Commit 1ffcd5e

Browse files
committed
fix dataview paging code (#43), fix grid paging errors to do with AllowAddNew and paging, add new updatePagingStatusFromView method to work around the hacky requirements for dataView.onPagingInfoChanged() (this breaks separation of concerns very slightly, but was a lesser evil. it will in any case default to existing behaviour)
1 parent ae82a13 commit 1ffcd5e

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
This is the acknowledged most active non-customised fork of SlickGrid.
44

5-
It aims to be a viable alternative master repo, building on the current state of the mleibman/SlickGrid master branch, keeping libraries up to date and applying small, safe core patches and enhancements without turning into a personalised build.
5+
It aims to be a viable alternative master repo, building on the legacy of the mleibman/SlickGrid master branch, keeping libraries up to date and applying small, safe core patches and enhancements without turning into a personalised build.
66

77
Check out the [examples](https://github.com/6pac/SlickGrid/wiki/Examples) for examples demonstrating new features and use cases, such as dynamic grid creation and editors with third party controls.
88

99
Also check out my [wiki](https://github.com/6pac/SlickGrid/wiki).
1010

11-
The following are the changes made since forking from the main MLeibman branch, a significant number in response to issues or pull requests.
11+
The following are the changes (most recent first) made since forking from the main MLeibman branch, a significant number in response to issues or pull requests.
1212

1313
**Maintenance:**
1414

15-
most recent first
16-
1715
* breaking change: updated jquery.event.drag-2.2.js and jquery.event.drop-2.2.js to be compatible with jQuery 3, bumped these to jquery.event.drag-2.3.0.js and jquery.event.drop-2.3.0.js
18-
* tested with jQuery 1.8.3, 1.11.2, 2.2.4, and 3.1.0
16+
* tested with jQuery 1.8.3, 1.11.2, 2.2.4, and 3.1.0 -- thanks to lfilho
1917
* updated repo to work with jQuery 3.x (without needing jQuery-Migrate) -- thanks to lfilho
2018
* fix bug with refresh last row of grid
2119
* fix bug in compound editor example 'isValueChanged' method

examples/example4-model.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,9 @@ <h2>View Source:</h2>
275275
});
276276

277277
dataView.onPagingInfoChanged.subscribe(function (e, pagingInfo) {
278-
var isLastPage = pagingInfo.pageNum == pagingInfo.totalPages - 1;
279-
var enableAddRow = isLastPage || pagingInfo.pageSize == 0;
280-
var options = grid.getOptions();
281-
282-
if (options.enableAddRow != enableAddRow) {
283-
grid.setOptions({enableAddRow: enableAddRow});
284-
}
278+
grid.updatePagingStatusFromView( pagingInfo );
285279
});
286280

287-
288281
var h_runfilters = null;
289282

290283
// wire up the slider to apply the filter to the model

slick.dataview.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,17 @@
762762
// get the current page
763763
var paged;
764764
if (pagesize) {
765-
if (filteredItems.length < pagenum * pagesize) {
766-
pagenum = Math.floor(filteredItems.length / pagesize);
765+
if (filteredItems.length <= pagenum * pagesize) {
766+
if (filteredItems.length === 0) {
767+
pagenum = 0;
768+
} else {
769+
pagenum = Math.floor((filteredItems.length - 1) / pagesize);
770+
}
767771
}
768772
paged = filteredItems.slice(pagesize * pagenum, pagesize * pagenum + pagesize);
769773
} else {
770774
paged = filteredItems;
771775
}
772-
773776
return {totalRows: filteredItems.length, rows: paged};
774777
}
775778

slick.grid.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ if (typeof Slick === "undefined") {
170170
var columnPosLeft = [];
171171
var columnPosRight = [];
172172

173-
173+
var pagingActive = false;
174+
var pagingIsLastPage = false;
175+
174176
// async call handles
175177
var h_editorLoader = null;
176178
var h_render = null;
@@ -1397,7 +1399,9 @@ if (typeof Slick === "undefined") {
13971399
}
13981400

13991401
function getDataLengthIncludingAddNew() {
1400-
return getDataLength() + (options.enableAddRow ? 1 : 0);
1402+
return getDataLength() + (!options.enableAddRow ? 0
1403+
: (!pagingActive || pagingIsLastPage ? 1 : 0)
1404+
);
14011405
}
14021406

14031407
function getDataItem(i) {
@@ -1705,7 +1709,8 @@ if (typeof Slick === "undefined") {
17051709
return;
17061710
}
17071711
vScrollDir = 0;
1708-
for (i = 0, rl = rows.length; i < rl; i++) {
1712+
rl = rows.length;
1713+
for (i = 0; i < rl; i++) {
17091714
if (currentEditor && activeRow === rows[i]) {
17101715
makeActiveCellNormal();
17111716
}
@@ -1802,9 +1807,15 @@ if (typeof Slick === "undefined") {
18021807
render();
18031808
}
18041809

1810+
function updatePagingStatusFromView( pagingInfo ) {
1811+
pagingActive = (pagingInfo.pageSize !== 0);
1812+
pagingIsLastPage = (pagingInfo.pageNum == pagingInfo.totalPages - 1);
1813+
}
1814+
18051815
function updateRowCount() {
18061816
if (!initialized) { return; }
18071817

1818+
var dataLength = getDataLength();
18081819
var dataLengthIncludingAddNew = getDataLengthIncludingAddNew();
18091820
var numberOfRows = dataLengthIncludingAddNew +
18101821
(options.leaveSpaceForNewRows ? numVisibleRows - 1 : 0);
@@ -1818,15 +1829,15 @@ if (typeof Slick === "undefined") {
18181829

18191830
// remove the rows that are now outside of the data range
18201831
// this helps avoid redundant calls to .removeRow() when the size of the data decreased by thousands of rows
1821-
var l = dataLengthIncludingAddNew - 1;
1832+
var r1 = dataLength - 1;
18221833
for (var i in rowsCache) {
1823-
if (i > l) {
1834+
if (i > r1) {
18241835
removeRowFromCache(i);
18251836
}
18261837
}
18271838
if (options.enableAsyncPostRenderCleanup) { startPostProcessingCleanup(); }
18281839

1829-
if (activeCellNode && activeRow > l) {
1840+
if (activeCellNode && activeRow > r1) {
18301841
resetActiveCell();
18311842
}
18321843

@@ -3621,6 +3632,7 @@ if (typeof Slick === "undefined") {
36213632
"getSelectedRows": getSelectedRows,
36223633
"setSelectedRows": setSelectedRows,
36233634
"getContainerNode": getContainerNode,
3635+
"updatePagingStatusFromView": updatePagingStatusFromView,
36243636

36253637
"render": render,
36263638
"invalidate": invalidate,

0 commit comments

Comments
 (0)