之前关于angular ui-grid过滤器设置,最近需要回顾,就顺便发到随笔上了
app.controller('MainCtrl',['$scope','$http',function ($scope,$http) {
$scope.gridOptions = {
columnDefs: [
{ field: 'name' },{ field: 'amount',name: 'Number',cellFilter: 'fractionFilter' },name: 'Currency',cellFilter: 'currencyFilter:this' }
]
};
原文链接:https://www.f2er.com/js/38787.html$scope.gridOptions = {
columnDefs: [
{ field: 'name' },{ field: 'amount',name: 'Number',cellFilter: 'fractionFilter' },name: 'Currency',cellFilter: 'currencyFilter:this' }
]
};
$http.get('data.json')
.success(function (data) {
$scope.gridOptions.data = data;
});
}])
.filter('fractionFilter',function () {
return function (value) {
return value.toFixed(0);
};
})
.filter('currencyFilter',function () {
var currencyMap = {
'dollar': '$','pound': '£','euro': '€'
};
return function (value,scope) {
return currencyMap[scope.row.entity.currency] + value.toFixed(2);
};
})