angularjs - I'm having trouble with ngTableParams refreshing -
i can't seem figure out refresh. can intial load of page, when function getactivity() run doesn't update page. @ loss. tried many different things no success.
this code below being called factory
uaappcommon.tableparams = function(data,sortfieldorder){ var table = new ngtableparams({ //page: 1, // show first page count: data.length, // count per page sorting: sortfieldorder }, { counts: [], //hides page sizes total: data.length, // length of data getdata: function($defer, params) { // use build-in angular filter var ordereddata = params.sorting() ? $filter('orderby')(data, params.orderby()) : data; $defer.resolve(ordereddata.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); return table; };
this snippet calling function within controller.
$scope.getactivity = function(numdays){ appservice.loadactivity(numdays) .then(function(response){ var activity = appservice.getactivity(); $scope.activitytable = appcommon.tableparams(activity,{date: 'desc'}); }); };
this html:
<table ng-table="activitytable" class="table" fixed-table-headers="scrollable-area"> <tr ng-repeat="act in $data"> <td data-title="'date & time'" sortable="'date'"> {{act.date}} </td> <td data-title="'activity'" sortable="'activity'">
can provide plunker? can check line in controller $scope.activitytable = appcommon.tableparams(activity,{date: 'desc'}); try replacing $scope.activitytable = uappcommon.tableparams(activity,{date: 'desc'});
and if doesn't work reload table yourtablename.reload() after function gets called.