在這種情況下,我們可以創建自定義過濾器,並將它注入到主模塊。此過濾器可以從其他應用程序的地方重新使用
首先創建一個過濾器模塊
angular.module('tmb.filter', []) //tmb is the main module
.filter('statusFilter', function() {
return function (type) {
return type ? 'Active' : 'In-Active';
};
});
然後注入到主模塊
var app = angular.module("tmb", ['ngRoute', 'ngGrid', 'tmb.services', 'tmb.filter']);
現在用它來NG-網格列
$scope.ConfigItemGrid = {
data: 'ConfigItemList',
primaryKey: 'ItemID',
multiSelect: false,
selectedItems: $scope.selectedUsers,
enableColumnResize: false,
showFooter: true,
footerRowHeight: 35,
enableCellEdit: false,
columnDefs: [
{ field: 'ItemDescription', displayName: 'Item Description', width: '25%', sortable: false },
{ field: 'IsPO', displayName: 'Is PO', width: '15%', sortable: false },
{ field: 'Status', displayName: 'Po Status', width: '15%', sortable: false, cellFilter: 'statusFilter' },
{ field: 'ItemType', displayName: 'Item Type', width: '25%', sortable: false },
{ filed: '', cellTemplate: '<button ng-click="edit(row, primaryKey)">Edit</button> <button ng-click="delete(row)">Delete</button>', width: '15%' }
]
};
那很簡短... –
是的,那很簡短,我想最好的方法是將另一個屬性添加到您的對象,根據位特性返回所需的值,或者準備一個函數來執行此操作。 請給我們一些代碼。 – Fedaykin