Skip to content

Commit

Permalink
feat: make onBeforePagingInfoChanged cancellable (mleibman#634)
Browse files Browse the repository at this point in the history
- similar to previous commit mleibman#625 make the `onBeforePagingInfoChanged` cancellable so that user could prevent the event bubbling and cancel the action
  • Loading branch information
ghiscoding authored Sep 6, 2021
1 parent 8fb38bd commit 5fa4d8c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions slick.dataview.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@
}

function setPagingOptions(args) {
onBeforePagingInfoChanged.notify(getPagingInfo(), null, self);

if (args.pageSize != undefined) {
pagesize = args.pageSize;
pagenum = pagesize ? Math.min(pagenum, Math.max(0, Math.ceil(totalRows / pagesize) - 1)) : 0;
}
if (onBeforePagingInfoChanged.notify(getPagingInfo(), null, self) !== false) {
if (args.pageSize != undefined) {
pagesize = args.pageSize;
pagenum = pagesize ? Math.min(pagenum, Math.max(0, Math.ceil(totalRows / pagesize) - 1)) : 0;
}

if (args.pageNum != undefined) {
pagenum = Math.min(args.pageNum, Math.max(0, Math.ceil(totalRows / pagesize) - 1));
}
if (args.pageNum != undefined) {
pagenum = Math.min(args.pageNum, Math.max(0, Math.ceil(totalRows / pagesize) - 1));
}

onPagingInfoChanged.notify(getPagingInfo(), null, self);
onPagingInfoChanged.notify(getPagingInfo(), null, self);

refresh();
refresh();
}
}

function getPagingInfo() {
Expand Down Expand Up @@ -1223,8 +1223,10 @@
refreshHints = {};

if (totalRowsBefore !== totalRows) {
onBeforePagingInfoChanged.notify(previousPagingInfo, null, self); // use the previously saved paging info
onPagingInfoChanged.notify(getPagingInfo(), null, self);
// use the previously saved paging info
if (onBeforePagingInfoChanged.notify(previousPagingInfo, null, self) !== false) {
onPagingInfoChanged.notify(getPagingInfo(), null, self);
}
}
if (countBefore !== rows.length) {
onRowCountChanged.notify({ previous: countBefore, current: rows.length, itemCount: items.length, dataView: self, callingOnRowsChanged: (diff.length > 0) }, null, self);
Expand Down

0 comments on commit 5fa4d8c

Please sign in to comment.