Range date filter was working before using server side

Range date filter was working before using server side

roineroine Posts: 14Questions: 0Answers: 0
edited May 2012 in General
Hi,

I am using this function to filter by date range

[code] $.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
if(typeof col[table].date == "number"){
var iMin = $('#min').val();
var iMax = $('#max').val();
var pDate = col[table].date;
var iVersion = aData[pDate] == "-" ? 0 : aData[pDate];
iVersion = iVersion.substr(0,10);
console.log(iVersion)
if ( iMin == "" && iMax == "" )
{
return true;
}
else if ( iMin == "" && iVersion <= iMax )
{
return true;
}
else if ( iMin <= iVersion && "" == iMax )
{
return true;
}
else if ( iMin <= iVersion && iVersion <= iMax )
{
return true;
}
return false;
}
else
return true;
}

);
$("#min").change(function(){
oTable.fnDraw();
})
$("#max").change(function(){
oTable.fnDraw();
})[/code]

Why this doesn't works? Before I was using getJSON to fetch my data and it was working, now I'm using server-side and doesn't works anymore, even though it return true.

Any clue are welcome.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    With server-side processing, the processing is done at the server-side :-). The client-side filtering plug-ins have no effect - you need to do the filtering on the server-side. So you would need to implement your filter in the server-side script.

    Allan
  • roineroine Posts: 14Questions: 0Answers: 0
    Thanks Allan!
  • roineroine Posts: 14Questions: 0Answers: 0
    edited May 2012
    Here is my server-side filter, works fine.

    [code]if((isset($_GET['min']) || isset($_GET['max'])) && ($_GET['min'] != '' || $_GET['max'] != '')){
    $min = mysql_real_escape_string($_GET["min"]);
    $max = mysql_real_escape_string($_GET["max"]);
    if ( $sWhere == "" )
    {
    $sWhere = "WHERE ";
    }
    else
    {
    $sWhere .= " AND ";
    }
    if(!isset($_GET["max"]) || $_GET['max'] == ''){
    $sWhere .= " created_at >= '$min' ";
    }
    if(!isset($_GET["min"]) || $_GET['min'] == ''){
    $sWhere .= " created_at <= '$max' ";
    }
    if(isset($_GET['min']) && isset($_GET['max']) && $_GET['min'] != '' && $_GET['max'] != ''){
    $sWhere .= " created_at BETWEEN '$min' AND '$max' ";
    }
    }[/code]
This discussion has been closed.