fnServerData is not working

fnServerData is not working

shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
edited March 2013 in General
i want to implement advance search on a populated table..here is what i have
[code]var oTable = $('#mytable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "server_processing.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
//my code
return nRow;
},
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "as_strno", "value": $('#strno').val() },
{ "name": "as_temp_ref", "value": $('#as_temp_ref').val() });
aoData.push( { "name": "dateaddedSto", "value": $('#listings_row #dateaddedSto').val() });
$.getJSON( sSource, aoData, function (json) {
fnCallback(json)
} );
}
} );


[/code]
what can be the issue in this code?

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited March 2013
    It's the $.getJSON part, I would think. Drawing the DataTable will already make an Ajax call if you have sAjaxSource set; you shouldn't need to explicitly invoke a jQuery Ajax method.

    The push itself looks like it should work. The server_processing.php will need to know how to extract those new parameters, as well. Make sure it's not a PHP issue.
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    its not clear..can you please write down what can i do?
    i have a popup window where user can select his parameter to search in datatable...
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    If you are just adding a couple of parameters, use fnServerParams to to that rather than overriding fnServerData .

    If that doesn't help, link to a test case.

    Allan
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    Hi Allan,
    i tried this but it is not workin
    "fnServerParams": function ( aoData ) {
    aoData.push( { "name": "id",
    "value": 1 } );

    },
    where id is the mysql table field in server_processing.php query..simple i wanted to get only that havind id=1
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    edited March 2013
    Let me make it very simple, on server_processing.php
    $aColumns = array('is_active','CompanyName', 'email', 'phone_no', 'web_address','id' );
    $sIndexColumn = "id";
    $sTable = "inf_company";
    also set connection to db, Now the jquery function is
    "sAjaxSource": "server_processing.php",
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    // Bold the grade for all 'A' grade browsers
    if ( aData[0] != 0 )
    {
    $('td:eq(0)', nRow).html( '' );
    }
    if ( aData[5] != 0 )
    {
    // $('td:eq(4)', nRow).html( 'A' ); // You can add your link here!!
    $('td:eq(5)', nRow).html( '' );
    }
    return nRow;
    },
    "fnServerParams": function ( aoData ) {
    aoData.push( { "name": "CompanyName",
    "value": "Debenhams" } );

    }
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Okay, that didn't work - so like I said - link to a test case so we can offer some help.

    Allan
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    Hi Allen,
    Please this is link

    http://pocketcityinfo.com/test/companylist.php
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Currently being sent to the server:

    > CompanyName=Debenhams

    Looks like it is working to me. Perhaps it is just the server-side script which is not applying the filtering correctly?

    Allan
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    edited March 2013
    Yes, Filter is not working, for serverside code i am using this code

    http://pocketcityinfo.com/test/code.txt
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    I can't help too much with that, but given that you aren't using the variable `CompanyName` - I'm not surprised it isn't working.

    If you are just trying to filer on the second column in your table, use fnFilter - if you are adding an additional query, you need to modify the $sWhere variable that is built.
  • shafiqkrshafiqkr Posts: 23Questions: 0Answers: 0
    can you please give me a complete example where some one have modify the $sWhere variable that is built?
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Certainly: http://datatables.net/support . The 1 hour option will cover the work involved I think.

    Allan
This discussion has been closed.