refresh JSON datasource (form search result) without using ajax

refresh JSON datasource (form search result) without using ajax

javabkjavabk Posts: 1Questions: 0Answers: 0
edited January 2013 in General
Hi, I have a search form that execute using ajax and return a JSON object (list) but can't figure out how to refresh the table with the new result, the table initially is empty,

I saw the custom var example http://datatables.net/examples/server_side/custom_vars.html but I don't want the dataTable to do the ajax request (unless there is a way to make my submit-search button trigger refresh on the table and make it pick my form values automatically ?)

thanks

Replies

  • bluehouseandrewbluehouseandrew Posts: 3Questions: 0Answers: 0
    I recently had to implement a table with 5,000 records and decided to use deferred rendering so that there is only the initial ajax request that returns the json encoded array. The table draws only what is needed for the initial display length and then the filter field and pagination will just automatically hit the json array and draw as needed. My initial load is less than 2 seconds and all table interaction after that is instantaneous.


    Example js
    [code]
    $('#demo').html( '' );
    var t = $('#demoTable').dataTable( {
    "sPaginationType": "full_numbers",
    "sAjaxSource": "/yourAjaxFunction.php",
    "bDeferRender": true,
    "iDisplayLength": 10,
    "aoColumns": [
    { "sTitle": "Column One Name" },
    { "sTitle": "Column Two Name" },
    { "sTitle": "Column Three Name" }
    ]
    } );
    [/code]

    Example PHP
    [code]
    $iTotal = count($Data);
    $output = array(
    "sEcho" => "1",
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => "10",
    "aaData" => array()
    );
    foreach ( $Data as $temp )
    {
    $row = array();
    $row[] = $temp['column_one'];
    $row[] = $temp['column_two'];
    $row[] = $temp['column_three'];
    $output['aaData'][] = $row;
    }

    echo json_encode($output);
    [/code]
This discussion has been closed.