date range filter with serverside data source

date range filter with serverside data source

d3vilr3dd3vilr3d Posts: 8Questions: 0Answers: 0
edited May 2010 in General
hi guys,

im trying to insert 2 input fields to filter my json sourced datatable. But I have no success following the example following the custom filter example. Can anyone point me at the right direction? thanks so much!

Replies

  • codingavenuecodingavenue Posts: 22Questions: 0Answers: 0
    Hi,

    Have you tried these? http://datatables.net/examples/server_side/custom_vars.html.

    codingavenue
  • d3vilr3dd3vilr3d Posts: 8Questions: 0Answers: 0
    Thanks so much!

    I made adjustment to my json generator file and it now parse the GET variables I pass it. One last question to make this perfect.

    How do I redraw table on keypress in this case? the sample code:

    [code]
    /* Add event listeners to the two range filtering inputs */
    $('#min').keyup( function() { oTable.fnDraw(); } );
    $('#max').keyup( function() { oTable.fnDraw(); } );
    [/code]

    is not grabbing the new input field value...
  • codingavenuecodingavenue Posts: 22Questions: 0Answers: 0
    Hi,

    Glad I could help. Could you post your js code?

    codingavenue
  • d3vilr3dd3vilr3d Posts: 8Questions: 0Answers: 0
    sure, here's what I have so far

    [code]
    var iMin = document.getElementById('min').value;
    var iMax = document.getElementById('max').value;
    var oTable = $('#data').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "list_processing.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some extra data to the sender */
    aoData.push( { "name": "start", "value": iMin, } );
    aoData.push( { "name": "end", "value": iMax, } );
    $.getJSON( sSource, aoData, function (json) {
    /* Do whatever additional processing you want on the callback, then tell DataTables */
    fnCallback(json)
    } );
    }
    });

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

    and in the list_processing.php, i have

    [code]
    /* Filtering */
    if( mysql_real_escape_string( $_GET['sSearch'] ) != "" AND $_GET['start'] != "" AND $_GET['end'] != ""){
    $sWhere .= "WHERE (tbl_list_2.from LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
    "tbl_list_2.to LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%') AND ".
    "(tbl_list_2.date >= $_GET[start] && tbl_list_2.date <= $_GET[end])";
    }
    elseif ($_GET['start'] != "" OR $_GET['end'] != ""){
    $sWhere .= "WHERE (tbl_list_2.date >= $_GET[start] && tbl_list_2.date <= $_GET[end])";
    }elseif ( mysql_real_escape_string( $_GET['sSearch'] ) != "")
    {
    $sWhere .= "WHERE (tbl_list_2.from LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
    "tbl_list_2.to LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%')";
    }
    [/code]
  • codingavenuecodingavenue Posts: 22Questions: 0Answers: 0
    Hi,

    I think the problem is that your iMin and iMax variables is set only once. So when 'keyup' event is fired, its still getting the data of iMin and iMax variables and not the current value of the two input fields.

    Hope that works.

    codingavenue
  • EmekaEmeka Posts: 13Questions: 0Answers: 0
    edited June 2010
    http://datatables.net/forums/comments.php?DiscussionID=2103&page=1#Item_3
  • EmekaEmeka Posts: 13Questions: 0Answers: 0
    can someone explain this line to me? Thanks,


    [code]var iVersion = aData[0] == "-" ? 0 : aData[0]*1;[/code]
  • codingavenuecodingavenue Posts: 22Questions: 0Answers: 0
    Hi,

    Having you tried your code without the custom filtering function?

    codingavenue
  • EmekaEmeka Posts: 13Questions: 0Answers: 0
    edited June 2010
    Yes, it works ok without custom filtering.
This discussion has been closed.