Matilda Yi Pan
Matilda Yi Pan

Reputation: 658

AngularJS smart table stSort "st-sort "not working

I am getting the data from $http, so it is asynchronously. And I did some search about this, the example I found : http://plnkr.co/edit/lzNtCDS5MhG8XHMArMDM?p=preview

Hence, I made my own plunker, using controller instead of directive. http://plnkr.co/edit/9MODgeySg10rPeMOmKaI?p=preview

Somehow, the st-sort is just not working.

Can you please take a look for me to see what I have done wrong?

var app = angular.module('myApp', []);

app.controller('Ctrl', ['$scope', '$timeout', function($scope, $timeout){

  $scope.name = "test";
  $scope.rowCollection = [];

  var initdata = [
    { name: 'Beta',  cc: '42', sn: '3456' },
    { name: 'Gamma', cc: '43', sn: '4675' }
  ];
  var data = [
    { name: 'Alpha', cc: '41', sn: '1234' },
    { name: 'Delta', cc: '49', sn: '2345' },
    { name: 'Beta',  cc: '42', sn: '3456' },
    { name: 'Gamma', cc: '43', sn: '4675' }
  ];

  $scope.isLoading = false;
  $scope.rowCollection = initdata
  $scope.displayCollection = [].concat($scope.rowCollection);

  $scope.formatNumber = function formatNumber(row) {
    return "+" + row.cc + "/" + row.sn;
  };

  $scope.isLoading = true;
  $timeout(function () {
      $scope.rowCollection = data;
      $scope.isLoading = false;
  }, 1000);


}]);

Upvotes: 2

Views: 834

Answers (1)

Michael
Michael

Reputation: 3104

I'm not familiar with smart-table, but you have to define the modul as a dependency to your application.

var app = angular.module('myApp', ['smart-table']);

Upvotes: 2

Related Questions