JSBin:http://live.datatables.net/nujehixu/3/edit?js,console,outputjQuery的數據表 - 自定義篩選基於原始行數據
$(document).ready(function() {
// push our custom filter onto the stack of filters
$.fn.dataTable.ext.search.push(function(settings, searchData, index, rowData, counter) {
// get filter value
var value = $("#example_filter > label > input").val().toLowerCase();
// check filter value against original row data
var original = rowData[1].toLowerCase();
console.log(original);
return original.indexOf(value) > -1;
});
function addEllipsis(original, charLimit) {
if (original.length > charLimit) {
// substring the original and add ellipsis with a title attribute of the original
return '<div title="' + original + '">' + original.substr(0, charLimit) + '…' + '</div>';
}
// return the original value since it is already short enough
return '<div title="' + original + '">' + original + '</div>';
}
var table = $('#example').DataTable({
columnDefs: [
{
targets: 1,
render: function (data, type, row) {
// render with ellipsis if necessary
return addEllipsis(data, 6);
}
}
]
});
});
退房鏈接的例子,我試圖使用基於原始行數據的自定義過濾器,但問題的表面時,輸入一個過濾器值,如systems
。當我期望systems
匹配「系統管理員」並顯示這些行時,系統管理員的行將被過濾掉。
通過source閱讀,它看起來像有第一貼靠搜索字符串,這是一個compiled from the rendered valuesglobal filter。
有沒有人找到解決方案?
你的意思是錯誤的過濾掉? –
@OlaviSau,我的意思是我希望系統與系統管理員匹配並顯示該行,但情況並非如此。我會編輯以更清楚地說明。 –
@JayTaggart - 已將代碼編輯到問題中。你應該真的在問題中包含一些代碼,特別是當問題是關於某些特定的代碼無法工作時。鏈接無法幫助未來的訪問者認識到問題,並且沒有人能確定您的鏈接將在3天,3個月或3年內持續或失效。 – davidkonrad