1
這裏是columnFilter數範圍過濾器的代碼:數據表columnFilter文本範圍搜索
function fnCreateRangeInput(oTable) {
//var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch;
th.html(_fnRangeLabelPart(0));
var sFromId = oTable.attr("id") + '_range_from_' + i;
var from = $('<input type="text" class="number_range_filter form-control" id="' + sFromId + '" rel="' + i + '"/>');
th.append(from);
th.append(_fnRangeLabelPart(1));
var sToId = oTable.attr("id") + '_range_to_' + i;
var to = $('<input type="text" class="number_range_filter form-control" id="' + sToId + '" rel="' + i + '"/>');
th.append(to);
th.append(_fnRangeLabelPart(2));
th.wrapInner('<span class="filter_column filter_number_range form-control" />');
var index = i;
aiCustomSearch_Indexes.push(i);
//------------start range filtering function
/* Custom filtering function which will filter data in column four between two values
* Author: Allan Jardine, Modified by Jovan Popovic
*/
//$.fn.dataTableExt.afnFiltering.push(
oTable.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
if (oTable.attr("id") != oSettings.sTableId)
return true;
// Try to handle missing nodes more gracefully
if (document.getElementById(sFromId) == null)
return true;
var iMin = document.getElementById(sFromId).value * 1;
var iMax = document.getElementById(sToId).value * 1;
var iValue = aData[_fnColumnIndex(index)] == "-" ? 0 : aData[_fnColumnIndex(index)] * 1;
if (iMin == "" && iMax == "") {
return true;
}
else if (iMin == "" && iValue <= iMax) {
return true;
}
else if (iMin <= iValue && "" == iMax) {
return true;
}
else if (iMin <= iValue && iValue <= iMax) {
return true;
}
return false;
}
);
//------------end range filtering function
$('#' + sFromId + ',#' + sToId, th).keyup(function() {
var iMin = document.getElementById(sFromId).value * 1;
var iMax = document.getElementById(sToId).value * 1;
if (iMin != 0 && iMax != 0 && iMin > iMax)
return;
oTable.fnDraw();
fnOnFiltered();
});
}
我怎麼能編輯它,這樣它會過濾掉不數範圍,但文本範圍?像可以說,在SQL
如果用戶輸入SELECT * FROM做WHERE
animal
之間BIRTH_CODE
'BC-01-01' 與 'BC-06-29'
FROM
:
BC-01-01
TO:BC-06-29