Having a min/max value filter for a numeric column

Having a min/max value filter for a numeric column

MetalKidMetalKid Posts: 2Questions: 0Answers: 0
edited December 2010 in General
While a bit difficult, it is possible to have min/max value filters for numerical values. The trick is trying to dynamically build a string that has the correct regular expression that forces the numbers to be in a specific range. This code will give you a minimum filter. I'm not sure how to incorporate the max at the same time, yet. At least not one that builds it dynamically like this:

[code]
$("#txtTest").keydown(function (e) {
// Need to handle delete/backspace scenario
// Need to handle normal number vs key-pad number
var val = $(this).val() + String.fromCharCode(e.keyCode);
var result = "(^";

for (i = 0; i < val.length; i++) {
if (i + 1 == val.length) {
result += "[" + val.charAt(i) + "-9]$";
}
else {
result += "[" + val.charAt(i) + "]";
}
}
result += "|";
for (i = 0; i < val.length; i++)
{
var temp = parseInt(val.charAt(i).toString()) + 1;
if (i == 0)
{
if (temp == 10) {
result += "[1][0-9]";
}
else {
result += "[" + temp + "]";
}
}
else {
result += "[0-9]";
}
}
result += ")";

// Use whatever number column you need
oTable.fnFilter(result, 4, true);
});
[/code]

Replies

  • MetalKidMetalKid Posts: 2Questions: 0Answers: 0
    Oh, nevermind. I missed this page:

    http://www.datatables.net/examples/plug-ins/range_filtering.html
This discussion has been closed.