Display parameters on url disable pagination on ngTable

I want to show the table parameters (page, score, filter, etc.) in the url. so I use the following code in the controller:

$scope.tableParams = new ngTableParams( angular.extend({ page : 1, count: 10 }, $location.search()), { getData: function ($defer, params) { $location.search(params.url()); // put params in url var query = getQuery(); query.limit = params.count(); query.offset = (params.page() - 1) * params.count(); getTotalCount().success(function () { Content.prototype.find(query) .success(function (response) { $scope.tableParams.total($scope.totalCount); var data = $filter('populateObjects')(response.data, query.fields); $defer.resolve(data); }); }); } }); 

I use pagination and server side filtering.

without the use of filters on the table everything goes fine, and pagination works correctly. but every time I apply a filter on a table, change the URL twice. for the first time this is normal. something like that:

 http://faraketabadmin/src/#/content/list?page=7&count=10&filter%5Bname%5D=g&filter%5Btype_id%5D=4 

but after a minute it will again reset to page 1 as follows:

 http://faraketabadmin/src/#/content/list?page=1&count=10&filter%5Bname%5D=g&filter%5Btype_id%5D=4 
+6
source share

Source: https://habr.com/ru/post/975984/


All Articles