Error when using fnServerData with server side processing

Error when using fnServerData with server side processing

raemrickraemrick Posts: 2Questions: 0Answers: 0
edited July 2013 in General
Hi all, I'm experiencing some issues when using server side processing along with fnServerData.

When using server side processing with fnServerData I receive all the data from the database (instead of just 10 rows at a time), and in the JSON that is returned I do not receive values for sEcho, iTotalRecords, or iTotalDisplayRecords. I have successfully implemented server side processing and fnServerData individually, errors only occur when they are combined. I've taken a look at this example http://datatables.net/examples/server_side/custom_vars.html but can't find anything out of the ordinary.

Client side:
[code]
var game_id = GetVar("game_id");
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "table/service/action_table_service.php",
"domTable": "#action_table",
"fields": [
{
"label": "Player Id:",
"name": "player_id"
}, {
"label": "Card Id:",
"name": "card_id"
}
]
} );
editor.on( 'onPreSubmit', function ( e, data ) {
data.game_id = game_id;
} );
$('#action_table').dataTable( {
"sDom": 'T<"clear">plfrtip',
"sAjaxSource": "table/service/action_table_service.php",
"bServerSide": true,
"sServerMethod": 'POST',
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "game_id", "value": "30" } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
})
},
"aoColumns": [
{ "mData": "player_id" },
{ "mData": "physical_card_id" }
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"sPaginationType": "full_numbers"
} );
} );
[/code]

Server side
[code]
<?php

include( "../../script/DataTables-1.9.4/extras/Editor-1.2.3/examples/php/lib/DataTables.php" );

use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;

if(isset($_GET["game_id"])) $game_id = $_GET["game_id"];
else if(isset($_POST["game_id"])) $game_id = $_POST["game_id"];

$editor = Editor::inst( $db, 'action', 'action_id' )
->fields(
Field::inst( 'physical_card_id' ),
Field::inst( 'player_id' )
)
->where($key="game_id", $value=$game_id, $op="=");

$out = $editor
->process($_POST)
->data();

echo json_encode( $out );
[/code]

Also want to say thanks for the great work allan, datatables and editor are awesome.

Replies

  • raemrickraemrick Posts: 2Questions: 0Answers: 0
    I was able to solve my problem by replacing fnServerData with fnServerParams.

    [code]
    "fnServerParams": function (aoData) {
    aoData.push( { "name": "game_id", "value": game_id } );
    }
    [/code]
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Good to hear you got the problem resolved!

    Regards,
    Allan
This discussion has been closed.