問題描述
是否可以僅對一個數據表應用某個過濾器?我在準備好文檔時應用了以下過濾器功能,我不知道這是否是正確的程序,但作為副作用,所有數據表都會受到過濾器的影響.我只想影響 $('#productTable'),但這個選擇器似乎沒有預期的效果.
Is it possible to apply a certain filter to only one datatable? I have the following filter function that I am applying on document ready, I don't know if this is proper procedure, but as a side effect all dataTables will be affected by the filter. I would Like to affect only the $('#productTable'), but this selector appears to not have the desired effect.
//Filter Function in Stock
//$('#productTable').
$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
var checked = $('#instock').is(':checked');
var qntStock = 1;
var stockCol = 3;
if (!checked) {
return true;
}
if (checked && aData[stockCol] > qntStock) {
return true;
}
return false;
});
是否可以僅對特定表應用過濾器?我該如何做到這一點?
Is it possible to apply a filter only to a particular table? How do I accomplish this?
數據表初始化:
var oTable = $('#productTable').dataTable({
"aoColumnDefs": [{
"sClass": "my_class",
"aTargets": [4]
}],
"bAutoWidth": false,
"iDisplayLength": 100,
"fnDrawCallback": function() {
$("td.my_class").editable(function(value, settings)
{
return(value);
},
{
indicator : 'Save...',
tooltip : 'Click to Edit...'
}
);
}
});
推薦答案
您可以創建一個表數組來進行過濾 - 然后在您的過濾器中檢查當前表是否存在于該數組中......類似于:
You could create an array of tables to have the filter - then in your filter check if the current table is present in that array ... something like :
// setup an array of the ids of tables that should be allowed
var allowFilter = ['productTable'];
$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
// check if current table is part of the allow list
if ( $.inArray( oSettings.nTable.getAttribute('id'), allowFilter ) == -1 )
{
// if not table should be ignored
return true;
}
var checked = $('#instock').is(':checked');
var qntStock = 1;
var stockCol = 3;
if (!checked) {
return true;
}
if (checked && aData[stockCol] > qntStock) {
return true;
}
return false;
});
這篇關于如何將過濾器應用于特定的數據表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!