Sfoglia il codice sorgente

TableAjax fix sort and filters

Piotr Labudda 10 anni fa
parent
commit
f0dcbe78bb
1 ha cambiato i file con 149 aggiunte e 124 eliminazioni
  1. 149 124
      SE/se-lib/TableAjax.php

+ 149 - 124
SE/se-lib/TableAjax.php

@@ -558,13 +558,10 @@ class TableAjax extends ViewAjax {
 		var _data; //columns and rows
 		var _currPage = 1; // current page
 		var _totalPages; // total pages
-		var _currSortCol; // current sorting column
-		var _currSortFlip = false; // current sorting direction
 		var _currDpOp; // clicked datetimepicker operator
-		var _filterCols = {}; // array with current filters /// TODO: mv to _state.filterCols
 		var _filterFields = {}; // array with filter DOM elements
 		var _filterTimeout; // timer for delayed filtering
-		var _uniqueCols = {}; // array with checked rows /// TODO: mv to _state.filterCols
+		var _uniqueCols = {}; // array with checked rows /// TODO: mv to _state.
 		var _checkToggleChecked = false; // check-all toggle state
 		var _exportFieldsSelect = {};
 
@@ -577,6 +574,10 @@ class TableAjax extends ViewAjax {
 			_uiNodeCont = priv.options.id;
 			_state = {};// init state
 			_state.specialFilters = {};
+			_state.filters = {};
+			_state.filters.currSortCol = '';
+			_state.filters.currSortFlip = false;
+			_state.filters.filterCols = {};
 			priv.initEvents();
 			priv.initialRender();// set up _uiNode$...
 			priv.options.types.string = ((priv.options.types || {}).string || {});
@@ -588,13 +589,8 @@ class TableAjax extends ViewAjax {
 				priv.options.mapEditorContainer = 'window';
 			}
 
-			if (priv.options.specialFilterFunctions && priv.options.filterInit) {
-				$.map(priv.options.specialFilterFunctions, function(groupObj, groupName) {
-					var fltrName = 'sf_' + groupName;
-					if (fltrName in priv.options.filterInit) {
-						_state.specialFilters[groupName] = priv.options.filterInit[fltrName];
-					}
-				});
+			if (priv.options.filterInit) {
+				priv.setStateFilters(priv.options.filterInit);
 			}
 
 			$.each(priv.options.exportFields, function(ind, col) {
@@ -1048,8 +1044,8 @@ class TableAjax extends ViewAjax {
 						}
 
 						//Add sort arrow
-						if (column == _currSortCol) {
-							if (_currSortFlip) $('<i class="glyphicon glyphicon-chevron-down pull-right"></i>').appendTo(headCell);
+						if (column == _state.filters.currSortCol) {
+							if (_state.filters.currSortFlip) $('<i class="glyphicon glyphicon-chevron-down pull-right"></i>').appendTo(headCell);
 							else $('<i class="glyphicon glyphicon-chevron-up pull-right"></i>').appendTo(headCell);
 						}
 
@@ -1081,8 +1077,8 @@ class TableAjax extends ViewAjax {
 					headCnt.appendTo(headCell);
 
 					//Add sort arrow
-					if (column == _currSortCol) {
-						if (_currSortFlip) headCell.addClass('ta-ordering-down');
+					if (column == _state.filters.currSortCol) {
+						if (_state.filters.currSortFlip) headCell.addClass('ta-ordering-down');
 						else headCell.addClass('ta-ordering-up');
 					}
 
@@ -1155,7 +1151,7 @@ class TableAjax extends ViewAjax {
 				tooltip = priv.options.types.bool.filterTooltip || 'Toggle between:<br/>indeterminate,<br/>checked,<br/>unchecked';
 				headCell = $('<th></th>').appendTo(node);
 				elem = $('<input class="filter indeterminate" checked type="checkbox" />').appendTo(headCell);
-				$.map(_filterCols, function (colProps, col) {
+				$.map(_state.filters.filterCols, function (colProps, col) {
 					if (col == "unique") {
 						if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
 						else if (!colProps.filter) elem.prop('checked', false).removeClass('indeterminate');
@@ -1271,7 +1267,7 @@ class TableAjax extends ViewAjax {
 					}
 
 					if (elem && props.filter) {
-						$.map(_filterCols, function (colProps, col) {
+						$.map(_state.filters.filterCols, function (colProps, col) {
 							if (col == column) {
 								if (colProps.col.type == 'bool') {
 									if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
@@ -1316,10 +1312,11 @@ class TableAjax extends ViewAjax {
 			if (priv.options.debug) console.log('Render: ', nodeClass);
 			node = $('<div class="foot-info ' + nodeClass + '"></div>');
 			//console.log('renderFooterInfo fromRow', _data.fromRow, 'toRow', _data.toRow, 'total', _data.total, '_currPage', _currPage, 'priv.options.pageSize', priv.options.pageSize);
-			_data.fromRow = (_currPage - 1) * priv.options.pageSize;
-			_data.toRow = _data.fromRow + priv.options.pageSize;
+			var fromRow = Math.max(_state.page - 1, 0) * _state.pageSize;
+			var total = _data.total;
+			var toRow = Math.min(fromRow + _state.pageSize, total);
 			if (_data.total > 0) {
-				$('<p>Wiersze od {0} do {1} z {2}</p>'.f(_data.fromRow + 1, Math.min(_data.toRow, _data.total), _data.total)).appendTo(node);
+				$('<p>Wiersze od {0} do {1} z {2}</p>'.f(fromRow + 1, toRow, total)).appendTo(node);
 			} else {
 				$('<p>Brak wierszy pasujących do kryteriów wyszukiwania</p>').appendTo(node);
 			}
@@ -1329,13 +1326,15 @@ class TableAjax extends ViewAjax {
 			var nodeClass = 'tblAjax__' + 'footer__toolbar__pagination',
 					currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
 					node;
-			if (priv.options.debug) console.log('Render: ', nodeClass, '_data.total', _data.total, '_currPage', _currPage);
+			var currPage = _state.page;
+			var totalPages = Math.ceil(_data.total / _state.pageSize);
+			if (priv.options.debug) console.log('Render: ', nodeClass, '_data.total', _data.total, 'currPage', currPage);
+/// console.log('Render: ', nodeClass, '_data.total', _data.total, 'currPage', currPage, '_state.page', _state.page);
 			if (_data.total > 0) {
 				node = $('<div class="btn-group ' + nodeClass + '"></div>');
-				var totalPages = Math.ceil(_data.total / priv.options.pageSize);
 				//create the pager.
-				var lowerPage = _currPage - 2;
-				var upperPage = _currPage + 2;
+				var lowerPage = currPage - 2;
+				var upperPage = currPage + 2;
 				if (upperPage > totalPages) {
 					var diff = upperPage - totalPages;
 					upperPage = totalPages;
@@ -1344,33 +1343,33 @@ class TableAjax extends ViewAjax {
 				if (lowerPage < 1) lowerPage = 1;
 				if (upperPage < 5) upperPage = 5;
 
-				//$('<li class="{0}"><a href="#">&lt;&lt;</a></li>'.f(_currPage == 1 ? 'disabled' : ''))
-				$('<button type="button" class="btn btn-default{0}">&lt;&lt;</button>'.f(_currPage == 1 ? ' disabled' : ''))
+				//$('<li class="{0}"><a href="#">&lt;&lt;</a></li>'.f(currPage == 1 ? 'disabled' : ''))
+				$('<button type="button" class="btn btn-default{0}">&lt;&lt;</button>'.f(currPage == 1 ? ' disabled' : ''))
 					.on('click', {pageIndex: 1}, priv.pageChanged)
 					.appendTo(node);
-				//$('<li class="{0}"><a href="#">&lt;</a></li>'.f(_currPage == 1 ? 'disabled' : ''))
-				$('<button type="button" class="btn btn-default{0}">&lt;</button>'.f(_currPage == 1 ? ' disabled' : ''))
-					.on('click', {pageIndex: _currPage - 1}, priv.pageChanged)
+				//$('<li class="{0}"><a href="#">&lt;</a></li>'.f(currPage == 1 ? 'disabled' : ''))
+				$('<button type="button" class="btn btn-default{0}">&lt;</button>'.f(currPage == 1 ? ' disabled' : ''))
+					.on('click', {pageIndex: currPage - 1}, priv.pageChanged)
 					.appendTo(node);
 
 				for (var i = lowerPage; i <= upperPage; i++) {
 					var link;
-					//if (i != _currPage) link = $('<li class="{1}"><a href="#">{0}</a></li>'.f(i, i > totalPages ? 'disabled' : ''));
-					if (i != _currPage) link = $('<button type="button" class="btn btn-default{1}">{0}</button>'.f(i, i > totalPages ? 'disabled' : ''));
-					//if (i == _currPage) link = $('<li class="active"><a href="#">{0}</a></li>'.f(i));
-					if (i == _currPage) link = $('<button type="button" class="btn btn-default active">{0}</button>'.f(i));
+					//if (i != currPage) link = $('<li class="{1}"><a href="#">{0}</a></li>'.f(i, i > totalPages ? 'disabled' : ''));
+					if (i != currPage) link = $('<button type="button" class="btn btn-default{1}">{0}</button>'.f(i, i > totalPages ? 'disabled' : ''));
+					//if (i == currPage) link = $('<li class="active"><a href="#">{0}</a></li>'.f(i));
+					if (i == currPage) link = $('<button type="button" class="btn btn-default active">{0}</button>'.f(i));
 
 					if (link) {
 						link.on('click', {pageIndex: i}, priv.pageChanged);
 						link.appendTo(node);
 					}
 				}
-				//$('<li class="{0}"><a href="#">&gt;</a></li>'.f(_currPage == totalPages ? 'disabled' : ''))
-				$('<button type="button" class="btn btn-default{0}">&gt;</button>'.f(_currPage == totalPages ? ' disabled' : ''))
-					.on('click', {pageIndex: _currPage + 1}, priv.pageChanged)
+				//$('<li class="{0}"><a href="#">&gt;</a></li>'.f(currPage == totalPages ? 'disabled' : ''))
+				$('<button type="button" class="btn btn-default{0}">&gt;</button>'.f(currPage == totalPages ? ' disabled' : ''))
+					.on('click', {pageIndex: currPage + 1}, priv.pageChanged)
 					.appendTo(node);
-				//$('<li class="{0}"><a href="#">&gt;&gt;</a></li>'.f(_currPage == totalPages ? 'disabled' : ''))
-				$('<button type="button" class="btn btn-default{0}">&gt;&gt;</button>'.f(_currPage == totalPages ? ' disabled' : ''))
+				//$('<li class="{0}"><a href="#">&gt;&gt;</a></li>'.f(currPage == totalPages ? 'disabled' : ''))
+				$('<button type="button" class="btn btn-default{0}">&gt;&gt;</button>'.f(currPage == totalPages ? ' disabled' : ''))
 					.on('click', {pageIndex: totalPages}, priv.pageChanged)
 					.appendTo(node);
 			} else {
@@ -1613,11 +1612,11 @@ class TableAjax extends ViewAjax {
 			if ('csv' == format) exportUrl += '&HEADER_NOT_INIT=YES';
 			exportUrl += '&format=' + format;
 			exportUrl += '&flds=' + exportFields.join(',');
-			exportUrl += '&sortCol=' + (_currSortCol || '');
-			exportUrl += '&sortDir=' + (_currSortFlip ? "desc" : "asc");
+			exportUrl += '&sortCol=' + (_state.filters.currSortCol || '');
+			exportUrl += '&sortDir=' + (_state.filters.currSortFlip ? "desc" : "asc");
 
-			if (Object.keys(_filterCols).length > 0) {
-				$.each(_filterCols, function (col, colProps) {
+			if (Object.keys(_state.filters.filterCols).length > 0) {
+				$.each(_state.filters.filterCols, function (col, colProps) {
 					if (colProps.filter && colProps.filter.length > 0) {
 						exportUrl += '&f_' + col + '=' + colProps.filter;
 					}
@@ -1656,29 +1655,23 @@ class TableAjax extends ViewAjax {
 			var initUrlAdd = '',
 				reqData = {},
 				filtersInitSet = false;
-			if (priv.options.filterInit) {
-				$.map(priv.options.filterInit, function (fltrProps, fltr) {
-					switch (fltr) {
-						case 'currSortCol':
-							_currSortCol = fltrProps;
-							initUrlAdd += '&currSortCol=' + fltrProps;
-							break;
-						case 'currSortFlip':
-							_currSortFlip = (fltrProps == 'desc')? true : false;
-							initUrlAdd += '&currSortFlip=' + fltrProps;
-							break;
-						default:
-							if (fltr.substr(0, 3) == 'sf_') {
-								reqData[fltr] = fltrProps;
-								filtersInitSet = true;
-							}
-							else if (fltr.substr(0, 2) == 'f_') {
-								reqData[fltr] = fltrProps;
-								filtersInitSet = true;
-							}
+			initUrlAdd += '&currSortCol=' + _state.filters.currSortCol;
+			initUrlAdd += '&currSortFlip=' + ((_state.filters.currSortCol)? "desc" : "asc");
+			if (Object.keys(_state.filters.filterCols).length > 0) {
+				$.each(_state.filters.filterCols, function (col, colProps) {
+					if (colProps.filter && colProps.filter.length > 0) {
+						initUrlAdd += '&f_' + col + '=' + colProps.filter;
+						filtersInitSet = true;
 					}
 				});
 			}
+			$.each(_state.specialFilters, function(groupName, btnValue) {
+				if (btnValue.length > 0) {
+					initUrlAdd += '&sf_' + groupName + '=' + btnValue;
+					filtersInitSet = true;
+				}
+			});
+
 			if (priv.options.forceFilterInit) {
 				$.map(priv.options.forceFilterInit, function (fltrProps, fltr) {
 					reqData['f_' + fltr] = fltrProps;
@@ -1697,13 +1690,11 @@ class TableAjax extends ViewAjax {
 					if (priv.options.debug) console.log('request finished L.<?php echo __LINE__; ?>');
 
 					// assign the new data
-					if (data.d && data.d.cols) {
-						priv.setStateCols(data.d.cols);
-					} else if (data && data.cols) {
+					if (data && data.cols) {
 						priv.setStateCols(data.cols);
 					}
 
-					// set initial filters (_filterCols)
+					// set initial filters (_state.filters.filterCols)
 					if (filtersInitSet && _data && _data.cols) {
 						$.map(reqData, function(fltrValue, fltr){
 							var colName = null;
@@ -1716,7 +1707,7 @@ class TableAjax extends ViewAjax {
 
 							if (colName && _data.cols[colName]) {
 								//add the filter to the filter array
-								_filterCols[colName] = {
+								_state.filters.filterCols[colName] = {
 									filter: fltrValue,
 									col: _data.cols[colName]
 								};
@@ -1726,16 +1717,12 @@ class TableAjax extends ViewAjax {
 
 					// assign the new state (data)
 					state = {data: {}};
-					if (data.d && data.d.cols) {
-						if (!skipCols) state.data.cols = data.d.cols;
-						state.data.rows = data.d.rows || [];
-						state.data.total = data.d.total || 0;
-					}
-					else {
-						if (!skipCols) state.data.cols = data.cols || {};
-						state.data.rows = data.rows || [];
-						state.data.total = data.total || 0;
-					}
+					if (!skipCols) state.data.cols = data.cols || {};
+					state.data.rows = data.rows || [];
+					state.data.total = data.total || 0;
+					state.page = data.page || 0;
+					state.pageSize = data.pageSize || priv.options.pageSize;
+					state.filters = data.filters || {};
 					priv.setState(state);
 
 					if (typeof callback == "function")
@@ -1753,25 +1740,47 @@ class TableAjax extends ViewAjax {
 		 assigns the new data.
 		 */
 		priv.setState = function (state) {
-			var oldState = _state,// TODO: use to check what really changed
-					renderParts = [];
+			var oldState = _state,// TODO: use to check what really changed (use extend!)
+					renderParts = {};
 			if (state.data) {
 				if (state.data.cols && state.data.cols.length > 0) {
 					priv.setStateCols(state.data.cols);
 					priv.setStateData(state.data);
-					renderParts.push('head');
+					renderParts['head'] = true;
 				} else {
 					priv.setStateData(state.data, true);
 				}
-				renderParts.push('body');
-				renderParts.push('foot_pagination');
+				renderParts['body'] = true;
+				renderParts['foot_pagination'] = true;
 			}
 			if (state.hasOwnProperty('specialFilters')) {
 				_state.specialFilters = state.specialFilters;
-				renderParts.push('head__specialFilters');
+				renderParts['head__specialFilters'] = true;
+			}
+			if (state.hasOwnProperty('page')) {
+				if (state.page != _state.page) {
+					_state.page = state.page;
+					renderParts['foot_pagination'] = true;
+				}
+			}
+			if (state.hasOwnProperty('pageSize')) {
+				if (state.pageSize != _state.pageSize) {
+					_state.pageSize = state.pageSize;
+					renderParts['foot_pagination'] = true;
+				}
+			}
+			if (state.hasOwnProperty('filters')) {
+/// console.log('L.<?php echo __LINE__; ?> setState::state.filters: ', state.filters);//TODO:DBG:RMME
+				priv.setStateFilters(state.filters);
+				// TODO: if state diff's
+				renderParts['head__specialFilters'] = true;
+				renderParts['foot_pagination'] = true;
 			}
 
+			renderParts = Object.keys(renderParts);
+
 			if (priv.options.debug) console.log('setState::renderParts: ', renderParts);//TODO:DBG:RMME
+///console.log('L.<?php echo __LINE__; ?> setState::renderParts: ', renderParts);//TODO:DBG:RMME
 			if (renderParts.length > 0) {
 				jQuery(_uiNodeCont).trigger('TableAjax:render', renderParts);
 			}
@@ -1815,6 +1824,32 @@ class TableAjax extends ViewAjax {
 			});
 		};
 
+		priv.setStateFilters = function(stateFilters) {
+			var newFilterCols = {},
+					newSpecialFilters = {};
+			$.map(stateFilters, function (fltrProps, fltr) {
+				switch (fltr) {
+					case 'currSortCol': _state.filters.currSortCol = fltrProps; break;
+					case 'currSortFlip': _state.filters.currSortFlip = (fltrProps == 'desc')? true : false; break;
+					default:
+						if (fltr.substr(0, 2) == 'f_') {
+							newFilterCols[fltr.substr(2)] = {
+								filter: fltrProps,
+								col: _data.cols[fltr.substr(2)]
+							};
+						}
+						else if (fltr.substr(0, 3) == 'sf_') {
+							var groupName = fltr.substr(3);
+							if (priv.options.specialFilterFunctions.hasOwnProperty(groupName)) {
+								newSpecialFilters[groupName] = fltrProps;
+							}
+						}
+				}
+			});
+			_state.filters.filterCols = newFilterCols;
+			_state.specialFilters = newSpecialFilters;
+		};
+
 		priv.setStateData = function (pData, skipCols, resetChecked) {
 			var data = $.extend(true, {}, pData);
 			data.fromRow = _data && _data.fromRow || 0;
@@ -1861,7 +1896,7 @@ class TableAjax extends ViewAjax {
 		 */
 		priv.filter = function () {
 			if (!priv.options.filter) return;
-			if (Object.keys(_filterCols).length == 0) return;
+			if (Object.keys(_state.filters.filterCols).length == 0) return;
 
 			publ.loadPage(0);
 		};
@@ -1870,8 +1905,8 @@ class TableAjax extends ViewAjax {
 		 sorts the data on the current sorting column
 		 */
 		priv.sort = function () {
-			if (!_data.cols[_currSortCol]) _currSortCol = "";
-			if (!_currSortCol) return;
+			if (!_data.cols[_state.filters.currSortCol]) _state.filters.currSortCol = "";
+			if (!_state.filters.currSortCol) return;
 
 			publ.loadPage(0);
 		};
@@ -1879,10 +1914,10 @@ class TableAjax extends ViewAjax {
 		/*
 		 helper that returns the underlying data by the unique value
 		 */
-		priv.getRow = function (unique) {
+		priv.getRow = function (uniqueValue) {
 			var row;
 			$.each(_data.rowsOrg, function (i, r) {
-				if (r[_state.uniqueCol] == unique) {
+				if (r[_state.uniqueCol] == uniqueValue) {
 					row = r;
 					return false;
 				}
@@ -1937,7 +1972,7 @@ class TableAjax extends ViewAjax {
 			}
 
 			//add the filter to the filter array
-			_filterCols[col.column] = {
+			_state.filters.filterCols[col.column] = {
 				filter: filter,
 				col: col
 			};
@@ -1956,7 +1991,7 @@ class TableAjax extends ViewAjax {
 			}
 
 			var filtersActive = false;
-			$.map(_filterCols, function (colProps, col) {
+			$.map(_state.filters.filterCols, function (colProps, col) {
 				if (colProps.filter.length > 0) {
 					filtersActive = true;
 					colProps.filter = '';
@@ -2106,7 +2141,7 @@ class TableAjax extends ViewAjax {
 						if (undefined !== _filterFields['the_geom']) {
 							var filter = 'BBOX:' + bounds.top + ',' + bounds.right + ',' + bounds.bottom + ',' + bounds.left;
 							_filterFields[column].val(filter);
-							_filterCols[column] = {
+							_state.filters.filterCols[column] = {
 								filter: filter,
 								col: _data.cols[column]
 							};
@@ -2232,18 +2267,19 @@ class TableAjax extends ViewAjax {
 		 */
 		priv.pageChanged = function (e) {
 			e.preventDefault();
-			if (e.data.pageIndex < 1 || e.data.pageIndex > _totalPages) return;
+			var currPage = _state.page;
+			var totalPages = Math.ceil(_data.total / _state.pageSize);
+			if (e.data.pageIndex < 1 || e.data.pageIndex > totalPages) return;
 
 			//set the new page
-			_currPage = e.data.pageIndex;
-			if (priv.options.debug) console.log('paging to index:{0} L.<?php echo __LINE__; ?>'.f(_currPage));
+			currPage = e.data.pageIndex;
 
 			//find out what rows to create
-			_data.fromRow = ((_currPage - 1) * priv.options.pageSize);
-			_data.toRow = _data.fromRow + priv.options.pageSize;
-			if (_data.toRow > _data.rows.length) _data.toRow = _data.rows.length;
+///			_data.fromRow = ((currPage - 1) * priv.options.pageSize);
+///			_data.toRow = _data.fromRow + priv.options.pageSize;
+///			if (_data.toRow > _data.rows.length) _data.toRow = _data.rows.length;
 
-			publ.loadPage(_currPage);
+			publ.loadPage(currPage);
 		};
 
 		/*
@@ -2261,7 +2297,6 @@ class TableAjax extends ViewAjax {
 			priv.options.pageSize = parseInt(val);
 
 			//revert to first page, as its gets messy otherwise.
-			_currPage = 1;
 			_data.fromRow = 0;
 			_data.toRow = _data.fromRow + priv.options.pageSize;
 			if (_data.toRow > _data.rows.length) _data.toRow = _data.rows.length;
@@ -2280,17 +2315,9 @@ class TableAjax extends ViewAjax {
 			if (priv.options.debug) console.log('col:{0} clicked'.f(e.data.column));
 
 			//set the new sorting column
-			if (_currSortCol == e.data.column) _currSortFlip = !_currSortFlip;
-			_currSortCol = e.data.column;
-
-			//trigger callback
-			if (typeof priv.options.columnClicked == 'function') {
-				priv.options.columnClicked.call(e.target, {
-					event: e,
-					column: _data.cols[_currSortCol],
-					descending: _currSortFlip
-				});
-			}
+			if (_state.filters.currSortCol == e.data.column) _state.filters.currSortFlip = !_state.filters.currSortFlip;
+			_state.filters.currSortCol = e.data.column;
+			/// TODO: var state = {}; state.currSortCol = ''; state.currSortFlip = ''; priv.setState(state);
 
 			_headSort = undefined;
 			_body = undefined;
@@ -2589,12 +2616,12 @@ class TableAjax extends ViewAjax {
 			var reqData = {
 				page: page,
 				pageSize: (pageSize || priv.options.pageSize),
-				currSortCol: (_currSortCol || ''),
-				currSortFlip: _currSortFlip ? "desc" : "asc"
+				currSortCol: (_state.filters.currSortCol || ''),
+				currSortFlip: _state.filters.currSortFlip ? "desc" : "asc"
 			};
 
-			if (Object.keys(_filterCols).length > 0) {
-				$.each(_filterCols, function (col, colProps) {
+			if (Object.keys(_state.filters.filterCols).length > 0) {
+				$.each(_state.filters.filterCols, function (col, colProps) {
 					if (colProps.filter && colProps.filter.length > 0) {
 						reqData['f_' + col] = colProps.filter;
 					}
@@ -2627,16 +2654,11 @@ class TableAjax extends ViewAjax {
 				async: true,
 				success: function (data) {
 					state = {data: {}};
-					if (data.d && data.d.cols) {
-						if (!skipCols) state.data.cols = data.d.cols;
-						state.data.rows = data.d.rows || [];
-						state.data.total = data.d.total || 0;
-					}
-					else {
-						if (!skipCols) state.data.cols = data.cols || {};
-						state.data.rows = data.rows || [];
-						state.data.total = data.total || 0;
-					}
+					state.data.rows = data.rows || [];
+					state.data.total = data.total || 0;
+					state.page = data.page || 0;
+					state.pageSize = data.pageSize || priv.options.pageSize;
+					state.filters = data.filters || {};
 					priv.setState(state);
 					_uiNode$Table.parent().parent().removeClass('AjaxTable-loading');
 				},
@@ -5222,6 +5244,9 @@ jQuery(document).ready(function(){
 		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">visibleCols (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($visibleCols);echo'</pre>';}
 
 		$jsonData = new stdClass();
+		$jsonData->page = $page + 1;
+		$jsonData->pageSize = $pageSize;
+		$jsonData->filters = $filters;
 		$jsonData->cols = new stdClass();
 		$ind = 0;
 		foreach ($visibleCols as $fieldID => $col) {