所有你已經粘貼代碼是在PHP,所以它不使用數據表的框架在所有搜索我打算假設你已經啓用了服務器端處理。
爲了從服務器端使用SQL NOT LIKE
做一個否定過濾器就好了,正如你試過的那樣,但是你所有的正負濾波器代碼都在相同的摘要循環中處理。我會添加另一個$_GET
,如$_GET['sSearch_type']
,以在完全獨立的循環中處理負濾波器。只要您可以在PHP MyAdmin(或您使用的任何SQL管理器)中重現查詢,使用單獨的$_GET
來控制搜索類型,在單獨的循環中設置查詢將不會有任何問題。
對於那些你們誰想要實際上使用數據表進行篩選,並需要負過濾器表達式: @Nate是有關使用regex
表達正確的,但執行不討論。
有兩種我知道以這種方式使用正則表達式的API方法。無論是fnFilter()
或search()
fnFilter()
已過時,你仍然可以使用它,但它是更好地使用上面寫着更換fnFilter()
的search()
API funcion。
文檔:
實施例:
// case insensitive filter a column for all
// values that don't match 'closed'
column.search('^(?!closed).*$', true, false, true).draw();
示例實現:
/**
* This example creates a select box filter which
* appends to the thead cell of the 3rd column
* from the left (i.e. column at index 2). The values
* of the select <option></option> are generated
* automatically based on the column's real values
* except for the 2 top most filters. The first is "All"
* which passes and empty string to the regex filter,
* and the second top most filter is "All Open Projects"
* which triggers the negative regex filter to remove
* all rows where the column value is set to "Closed"
* or "closed"
*/
$(document).ready(function() {
$('#report-table').DataTable({
initComplete: function() {
this.api().columns().every(function() {
var column_index = this[0][0],
column = this,
not_closed = 'not_closed',
select = $('<select id="status_col_filter" style="margin-left:10px;"><option value="">All</option><option value="'+ not_closed +'">All Open Projects</option></select>');
if (column_index === 2) {
select
.appendTo($(column.header()))
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
if (val === not_closed) {
// negative regex for all open status projects
column.search('^(?!closed).*$', true, false, true).draw();
} else {
// regular positive regex - filter by column value
column.search(val ? '^'+val+'$' : '', true, false).draw();
}
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="'+d+'">'+d+'</option>')
});
}
});
}
});
});
謝謝你的回覆,但不幸的是,這不是我正在尋找 – waa1990 2012-03-01 19:45:29