2016-04-20 31 views
0

我已經爲其中一列定義了條件單元格模板。它正確顯示數據,但我無法搜索單元格模板中的文本。 這裏是我的plunkr: https://plnkr.co/edit/TDX5jtPord1hkzCVaw3L?p=preview從單元格模板中搜索文本不工作在ui網格中

var template1 = '<div class="">' + 
'<div class="" ng-if="COL_FIELD > 30">Greater </div> ' + 
'<div class="" ng-if="COL_FIELD < 30"> Lesser </div> ' + 
'</div>'; 

在我已經把那個..如果COL_FIELD> 30,然後接着寫越大,條件模板..要不寫小。現在我應該能夠在數字列中搜索更大或更小的數字。

enter image description here

+0

在plnkr中定義COL_FIELD在哪裏? – tsuz

+0

COL_FIELD帶有ui-grid ..這實際上是渲染單元格模板之前該列的值。 – undefined

+0

我在plunkr中添加了模板,它顯示正常,所以我不理解你的問題是什麼。搜索欄在哪裏?你期望看到什麼,你在觀察什麼? – tsuz

回答

1

一個解決方案可能是您的數據添加屬性,如:

$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

+0

這爲我現在的目的..但有少數情況下,我必須需要定義模板..因爲特定的造型和其他東西..所以我想從該模板中搜索。無論如何,這現在對我有用。如果我沒有收到任何回覆,請回答這個問題。 – undefined

+0

我用另一個可能的解決方案更新了我的答案 – Lulylulu

+0

這就是我一直在尋找的東西。非常感謝。 – undefined

相關問題