How to refresh NG-Table loaded from an http request with dynamic data

Susy11 picture Susy11 · May 12, 2014 · Viewed 25.9k times · Source

I need to be able to refresh the data in my ng-table. The following images contain the full use case scenario. main view When a user clicks the search for BrandID, a new modal window apears: modal1

It contains an ng-table with some loaded data into it. After the modal is dismissed I click on the second search(GroupID), here the same modal window with an ng-table is opened but even if the request is ok and data is returned from the server, the loading fails: modal2

I would like to be able to refresh the table in order to initialize it with the newly received data.

The script in the Plunker is called each time the modal toggles.

Answer

erikt picture erikt · May 12, 2014

Try this to update table data:

$scope.tableParams.reload();

Edit: I found a possible bug in your code... I think you should change this:

var orderedData = params.sorting() ?
   $filter('orderBy')(filteredData, params.orderBy()) :
   $scope.datay;

to this:

var orderedData = params.sorting() ?
   $filter('orderBy')(filteredData, params.orderBy()) :
   filteredData;

Does that work better?