angularjsajaxsmart-table

Smart table - angularJs - ajax refresh table


I am using the angularjs mudule smart table.

My table has server-side processing and all the data load is located on the server. I want to have a refresh button outside of the table.

This is the function that makes a call to the server and I want to be able to call it manually, but I can't figure out how to retrieve the table state in the my controller.

this.callServer = function callServer(tableState) {

        ctrl.isLoading = true;

        var pagination = tableState.pagination;

        var start = pagination.start || 0;     // This is NOT the page number, but the index of item in the list that you want to use to display the table.
        var number = pagination.number || 10;  // Number of entries showed per page.

        service.getPage(start, number, tableState, ctrl.startDateFilter,
                ctrl.endDateFilter).then(function (result) {
            ctrl.displayed = result.data;
            tableState.pagination.numberOfPages = result.numberOfPages;
            ctrl.isLoading = false;
        });
    };

My goal is to have a function like this, How can I get the table state?

    this.refreshTable = function(){
        tableState = getTableState();
        ctrl.callServer(tableState);
    }

Solution

  • The solution is to put the table state in a controller variable.

    Everytime the callServer function is called, it will update this variable. This way, I am able to refresh the table.

        this.tableState = null;
    
        this.callServer = function callServer(tableState) {
            ctrl.tableState = tableState;
            ...
        }
    
        this.refreshGrid = function(){
            ctrl.callServer(ctrl.tableState);
        }