2016-01-27 88 views
0

我想排序列上的价值以美元(与$和,包括)的列上的网格,但排序无法正常工作 - 有没有办法让排序工作,或者如果有必要,将值设置为数字,然后显示为金钱?排序角度ui网格钱列

我有:

$scope.data = [ 
    { 'value': '$1,000,000' }, 
    { 'value': '$100,000' }, 
.... 
    { 'value': '$1,000' } 
]; 
$scope.gridOptions = { 
enableSorting: true, 
data: $scope.data, 
columnDefs: [ 
... 
    { name: 'Value', field: 'value', width: 110 } 
] 
+1

我觉得你的价值应该是在像平原号'100000'然后应用列'ui-grid'过滤器来显示格式化的货币值 –

+0

也许,它有助于http://stackoverflow.com/questions/14478106/angularjs-sorting-by-property –

+0

过滤器只是允许你过滤结果 - 你的意思是cellClass? –

回答

0

我没有看到你确切的HTML和其他JS代码,所以,我想自己单击列标题,按该列进行排序。如果您在代码中错过了什么,请包括它。我贴我的工作示例,

HTML代码,

<!doctype html> 
<html ng-app="app"> 
    <head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script> 
    <script src="http://ui-grid.info/release/ui-grid.js"></script> 
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css"> 
    <link rel="stylesheet" href="main.css" type="text/css"> 
    </head> 
    <body> 

<div ng-controller="MainCtrl"> 
    <br> 
    <br> 
    <div id="grid1" ui-grid="gridOptions1" class="grid"></div> 
    <br> 
</div> 
    <script src="app.js"></script> 
    </body> 
</html> 

JS代码

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']); 

app.controller('MainCtrl', ['$scope', '$http', 'uiGridConstants', function ($scope, $http, uiGridConstants) { 

    $scope.data = [ 
    { 'value': '$1,000,000' }, 
    { 'value': '$100,000' }, 
    { 'value': '$1,000' } 
]; 
    $scope.gridOptions1 = { 
    enableSorting: true, 
    columnDefs: [ 
     { field: 'value', 
     name:'value'}, 
    ], 
    }; 
     $scope.gridOptions1.data = $scope.data; 
}]);