0

I am using angular js smart table in my application. Every thing works fine during initial load. However I have a button (it is outside smart table) to refresh the data when some of the criteria changes. On button click I am calling changeView function which repopulates rowCollection data as shown below. As per my knowledge in angular js, this data change should be reflected in view (two-way data binding).

But after button click, only headers are appearing in my smart table, all the remaining data is getting removed. Can any one point me what is the flaw in my approach? getKPIModesData is retuning the required json data in correct format, there is no problem with that.

$scope.changeView = function(selectedAccount, selectedCarrierList, fromDate, toDate) {
                        $scope.rowCollection = DashboardsDataService.getKPIModesData(selectedAccount, selectedCarrierList, fromDate, toDate);                                               

                    }
Madasu K
  • 1,813
  • 2
  • 38
  • 72
  • are you returning a promise from getKPIModesData function? – khizar naeem Sep 19 '14 at 11:26
  • No. I have not used any promises. is it mandatory to use to get the data from services? – Madasu K Sep 19 '14 at 11:33
  • 1
    it is a good practice, and btw use console.log($scope.rowCollection ) after this line $scope.rowCollection = DashboardsDataService.getKPIModesData(selectedAccount, selectedCarrierList, fromDate, toDate); and tell me if you still see the data you want to see – khizar naeem Sep 19 '14 at 11:35
  • 1
    Now I realized the importance of the promises. console.log($scope.rowCollection )is not returning data which I want. In the service the ajax function call is returning correct json data but some other part of the code is effecting to return this data to my controlelr which I had over looked. Thanks for your help. – Madasu K Sep 19 '14 at 11:48

1 Answers1

4

make sure

  1. you use the st-safe-src attribute so that smart-table watches your collection and is able to update its reference copy whenever you load/update your data.
  2. the displayed collection is different from the safe source collection otherwise you will enter an infinite loop.

You'll find more details (and a plunkr) on this github issue

laurent
  • 2,590
  • 18
  • 26