lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 513 forks source link

Paginate by using url params #750

Closed johnico closed 7 years ago

johnico commented 7 years ago

angular version- 1.5.10 smart table- latest version

HI I am trying to paginate the user to the page by keep the last page in the url I managed to save the "start" in the url - for example for page 2 i'm saving 20 and page 3 Im saving 30 ?startPage=20

and then I tried to set tablestate.pagination.start = 10 for exmaple the problem is the page is stuck of course on the same page

my Question i how can I the the param from the url and paginate the user to this page ( again I manages to keep the state and start param in every page) the problem is in the loading that i need to take from the url , and when paginate between page after I set the tablestate.pagination.start = param url

I don't want to use local storage cause I need it by url

 this.callServer = function callServer(tableState) {

  tableState.pagination.start = **urlParams**;
    vm.isLoading = true;
    var pagination = tableState.pagination;
    var start = pagination.start || 0;  
    var number = pagination.number || 10

 /** this cubmir the search on table from external filter**/
    vm.submit = function (){
        vm.isLoading = true;

        serverCall(0, 10, tableState,searchObj);
        tableState.pagination.start = 0;
    }
    serverCall(start, number, tableState,searchObj);

  };

thx a lot

MrWook commented 7 years ago

Hello @johnico,

i think you mean with:

the problem is the page is stuck of course on the page

that you stuck on the page that you start with and not on the first page?

That is because you set the tableState.pagination.start everytime the SmartTable callServer function is triggered. So every time you try to go to the next page the tableState.pagination.start is set to the url parameter again. I think it should work if you wrapp it around a if statement to check if it's the first time the table is loaded

if(!$scope.firstLoadIsDone) {
    tableState.pagination.start = **urlParams**;
    $scope.firstLoadIsDone = true;
}
johnico commented 7 years ago

thx @MrWook . yes that what i meant , the state changed every time

I need that in the first time the table will paginate to the url param . and will update the param in every change until the next refresh

johnico commented 7 years ago

@MrWook do you know how can I do the same with the sort? to set default sort instead of hard code sort

MrWook commented 7 years ago

@johnico

Is the problem fixed with my recommendation?

If my recommendation fixed the problem i would say that this should work for the sorting too:

if(!$scope.firstLoadIsDone) {
        tableState.pagination.start = **urlParams**;
    tableState.sort.predicate = **urlParams column**;
    tableState.sort.reverse = **urlParams true or false**;

    $scope.firstLoadIsDone = true;
}
johnico commented 7 years ago

@MrWook hi thx . its not working- i think because the function called twice Why the this.callserver called twice? I also checked and I have no ng-controller (defined in the route)

maybe its because the pagination or using st-sort-default directive. ? How can I solve it thx for the helping

johnico commented 7 years ago

Hi everything is working now with adding the following code:

.config([ 'stConfig', function(stConfig) { stConfig.sort.delay = 100; stConfig.pipe.delay = 200; }])