1
我正在一個jQuery數據表項目,我需要根據特定的行類過濾數據。我在創建行時根據條件將類添加到我的行中。我試圖找出一種方法讓我的用戶單擊一個按鈕,該按鈕將應用僅顯示包含特定類的行的過濾器。jQuery數據表格篩選器行與特定類
我試過幾種不同的解決方案,但我似乎無法使它工作。有誰知道如何正確地做到這一點?
這裏是JSFiddle
$('#table').DataTable({
data: data,
columns: [
{
"data": "item1",
"render": function (data, type, row) {
if(type === 'display'){
return "<span class='format1'>"+data+"</span>";
}else if(type === 'sort'){
return data;
}else if(type === 'filter'){
return data;
}else{
return data;
}
}
},
{
"data": "item2",
"render": function (data, type, row) {
if(type === 'display'){
return "<span class='format2'>"+data+"</span>";
}else if(type === 'sort'){
return data;
}else if(type === 'filter'){
return data;
}else{
return data;
}
}
}
],
createdRow: function (row, data, index) {
if (data.item2 == 'this is item 2 - meets condition1') {
$(row).addClass('condition1');
}
if (data.item2 == 'this is item 2 - meets condition2') {
$(row).addClass('condition2');
}
}
});
$('#btn-filter').on('click',function(){
//// only show table data that contains the class condition1
});
$('#btn-undo').on('click',function(){
//// remove the filter that was applied with btn-filter
});
真棒......這就是我一直在尋找。 'pop()'如何工作?它只是刪除最後設定的搜索或所有搜索。 – Austin
很高興我能幫上忙。 'pop()'函數清除迄今爲止應用的過濾器... –