Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


ngtable dynamic data not working with sorting using -'angularjs,ngtable'


ngtable dynamic data not working with sorting  using -'angularjs,ngtable'

I want to use ngTable to display dynamic data inside a table that is sortable. My data is available as an array inside a service. This array gets updated from another controller. The ngTable uses a method of this service to get the data to display:

$scope.tableParams = new NgTableParams({
  sorting: {
    name: 'asc'
  }
},
{
  getData: function(params) {
    var data = MyService.getData();
    return data;
  }
});


This works perfectly fine. Whenever the data inside my service gets changed, ngTable automatically detects this and updates the table. Now I want to implement sorting and I modified the following line:

var data = MyService.getData();


to

var data = params.sorting() ? $filter('orderBy')(MyService.getData(), params.orderBy()) : MyService.getData();


The problem here is that now ngTable does not detect that the data in MyService got changed. I think this has something to do with the $watch functionality that ngTable uses to detect data changes.

How can I fix that? I saw that ngTable has a refresh() method that allows me to call whenever I want the table to refresh, but I can't find a location to do so, because: MyService holds the data and gets refreshed by another controller. But MyService has no access to the controller holding the ngTable..
    

asked Sep 7, 2015 by rajesh
0 votes
17 views



Related Hot Questions



Government Jobs Opening


...