一個解決方案可能是您的數據添加屬性,如:
$http.get('data.json').success(function(data) {
data.map(function(item) {
item.greaterLesser = item.amount > 30 ? 'Greater' : 'Lesser';
});
$scope.gridOptions.data = data;
});
,然後而是採用與模板的量,只要綁定這個屬性。
$scope.gridOptions = {
enableFiltering: true,
columnDefs: [{
field: 'name',
width: 70
}, {
field: 'greaterLesser',
name: 'Number',
width: 90,
}, {
field: 'amount',
name: 'Currency',
cellFilter: 'currencyFilter:this',
}]
};
這裏是updated plunker
編輯
如果你想使用的模板,你可以實現你自己的搜索功能。您可以將filter
選件添加到您的字段並實現condition
函數。喜歡的東西:
filter: {
condition: function(searchTerm, cellValue) {
var value = cellValue > 30 ? 'greater' : 'lesser';
var result = value.search(searchTerm.toLowerCase());
return result > -1;
}
}
這裏我用了search
功能,但你可以使用match
或其他一些功能。 這裏是demo plunker
在plnkr中定義COL_FIELD在哪裏? – tsuz
COL_FIELD帶有ui-grid ..這實際上是渲染單元格模板之前該列的值。 – undefined
我在plunkr中添加了模板,它顯示正常,所以我不理解你的問題是什麼。搜索欄在哪裏?你期望看到什麼,你在觀察什麼? – tsuz