Numeric Values Filtering

Numeric Values Filtering

wesimywesimy Posts: 1Questions: 0Answers: 0
edited February 2012 in DataTables 1.8
i have been looking for the past few hours for a solution for filtering " Numeric fields "

i have created some custom filters for each column and bind the keyup to fnFilter() fucntion
[code]
$("thead input").keyup(function () {
matrix.fnFilter(this.value, $("thead input").index(this));
});
[/code]

Which did the job for columns that has Non Numeric values but when i search fields with Numeric values it acts as string even though i set the column type as "numeric"

i have figure out that you use test(sData) to filter rows which 't consider Numeric values as a string. so i have added a piece of code that did the job for my problem and i thought it would be useful to implement it in a better way maybe in the feature releases. or maybe you have something already for my case which i am not aware of .

here is my modifications to the function _fnFilterColumn in line 4045
[code]
if (oSettings.aoColumns[iColumn].sType != "numeric") {
if (!rpSearch.test(sData)) {

oSettings.aiDisplay.splice(i, 1);
iIndexCorrector++;
}
}
else {
//// Added By Moataz *
//// To add Numiric Search Support to filters
if (sData < Number(sInput)) {
oSettings.aiDisplay.splice(i, 1);
iIndexCorrector++;
}

}
}
[/code]

Basically i check the sType and if it is numeric i would filter it as Number and compare the values as integers and show all the values larger than my inpute.

so if i search 5 and i have values [1,3,5,7,9] it will only show [5,7,9]

you sure can compare the exact values or add even more details such as having the option to use operators such as < , > into the input


Regards
This discussion has been closed.