javascript - Angular JS sorting and converting strings to integers -


i'm facing , issue here cant seem around. have json contains array of people , inside each person array of strings. in array have numbers , actual string values. integers being treated strings when use orderby sorts incorrectly because thinks integers strings.

what trying figure out of way can convert strings integers using ng-repeat spit out integers.

here current html:

<div ng-controller="tablectrl">     <p><strong>page:</strong> {{tableparams.page()}}</p>         <p><strong>count per page:</strong> {{tableparams.count()}}</p>     <table ng-table="tableparams">         <tr ng-repeat="person in $data">         <td data-title="'name'" sortable="'0'">{{person[0]}} {{person[1]}}</td>         <td data-title="'age'" sortable="'2'">{{ person[2] }}</td>         </tr>     </table> </div> 

current json structure:

0: array[3] 0: "john" 1: "doe" 2: "25" 

my javascript:

angular.module("myapp").controller('tablectrl', ['$scope', '$http', 'ngtableparams', '$filter',          function($scope, $http, ngtableparams, $filter) {             $scope.people= {};             $scope.tableparams = new ngtableparams({                 page: 1, // show first page                 count: 10 // count per page             }, {                 total: 0, // length of data                 getdata: function($defer, params) {                     $http({                         method: 'get',                         url: "json.url.json"                     })                         .success(function(data, status, headers, config) {                              $scope.tableparams.total(data.length)                              $scope.people= data;                              var ordereddata = params.sorting() ?                                 $filter('orderby')(data, params.orderby()) :                                 data;                              $defer.resolve(ordereddata.slice((params.page() - 1) * params.count(), params.page() * params.count()));                         })                         .error(function(data, status, headers, config) {                             // went wrong :(                         });                 }             });         }     ]); 

currently using http://bazalt-cms.com/ng-table/ try , execute table , sorting functionality.

i preprocessing on data comes in create fields able sorted, etc.

angular.foreach(data,function(el,i){   el.age_int = parseint(el.age); });  $scope.people = data; 

then can use new field sorting or requires integers on strings.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -