Commit 9ed45f15 authored by Elliot Pahl's avatar Elliot Pahl Committed by Nigel McNie
Browse files

Make tablerenderer remember the last arguments when using the pager.

parent 0e54b5b9
...@@ -26,6 +26,7 @@ function TableRenderer(target, source, columns, options) { ...@@ -26,6 +26,7 @@ function TableRenderer(target, source, columns, options) {
this.rowfunction = function(rowdata, rownumber, data) { return TR({'class': 'r' + (rownumber % 2)}); } this.rowfunction = function(rowdata, rownumber, data) { return TR({'class': 'r' + (rownumber % 2)}); }
this.updatecallback = function () {}; this.updatecallback = function () {};
this.updateOnLoadFlag = false; this.updateOnLoadFlag = false;
this.lastArgs = {};
this.init = function() { this.init = function() {
self.table = getElement(target); self.table = getElement(target);
...@@ -116,9 +117,8 @@ function TableRenderer(target, source, columns, options) { ...@@ -116,9 +117,8 @@ function TableRenderer(target, source, columns, options) {
} }
this.pageChange = function(n) { this.pageChange = function(n) {
self.doupdate({ self.lastArgs.offset = ( n - 1 ) * self.limit;
'offset': ( n - 1 ) * self.limit self.doupdate(self.lastArgs);
});
} }
this.onFirstPage = function () { this.onFirstPage = function () {
...@@ -175,6 +175,7 @@ function TableRenderer(target, source, columns, options) { ...@@ -175,6 +175,7 @@ function TableRenderer(target, source, columns, options) {
if (!request_args) { if (!request_args) {
request_args = {}; request_args = {};
} }
self.lastArgs = request_args;
forEach(self.statevars, function(key) { forEach(self.statevars, function(key) {
if (typeof(request_args[key]) == 'undefined' && typeof(self[key]) != 'undefined') { if (typeof(request_args[key]) == 'undefined' && typeof(self[key]) != 'undefined') {
...@@ -230,16 +231,19 @@ function TableRenderer(target, source, columns, options) { ...@@ -230,16 +231,19 @@ function TableRenderer(target, source, columns, options) {
}; };
this.goFirstPage = function() { this.goFirstPage = function() {
self.doupdate({'offset': 0}); self.lastArgs.offset = 0;
self.doupdate(self.lastArgs);
}; };
this.goPrevPage = function() { this.goPrevPage = function() {
if ( self.offset > 0 ) { if ( self.offset > 0 ) {
if ( self.offset - self.limit < 0 ) { if ( self.offset - self.limit < 0 ) {
self.doupdate({'offset': 0}); self.lastArgs.offset = 0;
self.doupdate(self.lastArgs);
} }
else { else {
self.doupdate({'offset': self.offset - self.limit}); self.lastArgs.offset = self.offset - self.limit;
self.doupdate(self.lastArgs);
} }
} }
else { else {
...@@ -249,7 +253,8 @@ function TableRenderer(target, source, columns, options) { ...@@ -249,7 +253,8 @@ function TableRenderer(target, source, columns, options) {
this.goNextPage = function() { this.goNextPage = function() {
if ( self.offset + self.limit < self.count ) { if ( self.offset + self.limit < self.count ) {
self.doupdate({'offset': self.offset + self.limit}); self.lastArgs.offset = self.offset + self.limit;
self.doupdate(self.lastArgs);
} }
else { else {
logWarning('Already on the last page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')'); logWarning('Already on the last page (' + self.offset + ', ' + self.limit + ', ' + self.count + ')');
...@@ -257,7 +262,8 @@ function TableRenderer(target, source, columns, options) { ...@@ -257,7 +262,8 @@ function TableRenderer(target, source, columns, options) {
}; };
this.goLastPage = function() { this.goLastPage = function() {
self.doupdate({'offset': Math.floor( ( self.count - 1 ) / self.limit) * self.limit}); self.lastArgs.offset = Math.floor( ( self.count - 1 ) / self.limit) * self.limit;
self.doupdate(self.lastArgs);
}; };
this.updateOnLoad = function() { this.updateOnLoad = function() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment