rifanece / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

Number-range filter not working #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set up table with number range filtering on a column 
2. Enter values in number range filter boxes

What is the expected output? What do you see instead?

Expect to show filtered results but always shows "No matching records found" 
even when match is expected

What version of the product are you using? On what operating system?

1.4.7 Windows 7

Please provide any additional information below.

All other filter types working as expected, even when alongside a number-range 
column.

Original issue reported on code.google.com by robert.h...@iesve.com on 6 Jun 2012 at 10:54

GoogleCodeExporter commented 9 years ago
Same issue here plus pagination produces this issue, so when I go to the next 
page all rows disappear. 
I'm using server-side processing.

JQuery: 1.7.1
DataTables: 1.9.2
ColumnFilter: 1.4.8

Original comment by arnold.l...@gmail.com on 14 Jul 2012 at 8:45

GoogleCodeExporter commented 9 years ago
Hi,

It works fine on 
http://jquery-datatables-column-filter.googlecode.com/svn/trunk/numberRange.html
 Could you send me some online example?

Thanks,
Jovan

Original comment by joc...@gmail.com on 15 Jul 2012 at 11:41

GoogleCodeExporter commented 9 years ago
Further investigation has revealed the cause in my case.

The data in the table was wrapped in span tags, causing problems in 
oTable.dataTableExt.afnFiltering.push

My fix was to add:

aData[_fnColumnIndex(index)] = 
aData[_fnColumnIndex(index)].replace("<span>","");
aData[_fnColumnIndex(index)] = aData[_fnColumnIndex(index)].replace("</span>", 
"");

after: 

var iMax = document.getElementById(sToId).value * 1;

in that function

Original comment by robert.h...@iesve.com on 18 Jul 2012 at 9:43

GoogleCodeExporter commented 9 years ago
Thanks for help.
I figured out that my problem was I didn't parse the range input for server 
side processing.
So the query looked like: ....LIKE '%s~s%'

In the server-side processing script i added:
/* Individual column filtering */
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
       if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
         {
            if ( $sWhere == "" )
            {
                $sWhere = "WHERE ";
            }
            else
            {
                $sWhere .= " AND ";
            }
            //$sWhere .= "".$cColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
            $columnFilterValue = mysql_real_escape_string($_GET['sSearch_' . $i]);
            // check for values range
            $rangeSeparator = "~";
            if (!empty($rangeSeparator) && strstr($columnFilterValue, $rangeSeparator)) {
                // get min and max

                 $columnFilterRangeMatches =  explode('~', $columnFilterValue);

                // get filter
                if (empty($columnFilterRangeMatches[0]) && empty($columnFilterRangeMatches[1]))
                    $sWhere .= " 0 = 0 ";
                else if (!empty($columnFilterRangeMatches[0]) && !empty($columnFilterRangeMatches[1]))
                    $sWhere .= $cColumns[$i] . " BETWEEN '" . $columnFilterRangeMatches[0] . "' and '" . $columnFilterRangeMatches[1] . "' ";
                else if (empty($columnFilterRangeMatches[0]) && !empty($columnFilterRangeMatches[1]))
                    $sWhere .= $cColumns[$i] . " <= '" . $columnFilterRangeMatches[1] . "' ";
                else if (!empty($columnFilterRangeMatches[0]) && empty($columnFilterRangeMatches[1]))
                    $sWhere .= $cColumns[$i] . " >= '" . $columnFilterRangeMatches[0] . "' ";
            } else {
                $sWhere .= $aColumns[$i] . " LIKE '%" . $columnFilterValue . "%' ";
            }
        }
    }

and the range-filter is working :)

Original comment by arnold.l...@gmail.com on 18 Jul 2012 at 10:11

GoogleCodeExporter commented 9 years ago
Hi,

I will assume that this issue can be closed. 
1. number range forks only with numbers so make sure that you do not use span 
tags. I cannot handle all possible design choices in filter.
2. Second issue is reasolved as I see.

Thanks,
Jovan

Original comment by joc...@gmail.com on 4 Sep 2012 at 8:08