Gossamer Forum
Quote Reply
Re: [gotze] JSON In reply to
   

Dear Andy

actually it can do a bit more than sorting in client side.
it will also reduce the server load and save a lot of bandwidth

some grid has zebra stripe, totalality counting , single or mutiple line select
,Pagination ,sorting, fixed table head, cell data modification....


here is the perl sample code from the offcical site.
http://www.datatables.net/...rver-side/perl_mysql


it's output looks like this

blah blah

Code:

my %sOutput = (
sEcho => int($q->param('sEcho')),
iTotalRecords => int($iTotal),
iTotalDisplayRecords => int($iFilteredTotal),
aaData => \@aaData,
);
return $self->to_json(\%sOutput);
} # /table_data



so basiclly i need to have sEcho iTotalRecords iTotalDisplayRecords aaData ready.

so i mimic its jason pattern to use following simple scripts to produce a jason response from perl.

Code:

#!c:/perl/bin/perl.exe
## modules json test,
use CGI;
use strict;
use warnings;

# read the CGI params
my $cgi = CGI->new;
my $sEcho = $cgi->param("sEcho");
my $username = "myname";
# create a JSON string according to the database result

$sEcho = int( $sEcho );
my $json =qq{{ "sEcho": $sEcho, "iTotalRecords": 5, "iTotalDisplayRecords": 5, "aaData": [ ["Trident","Internet Explorer 4.0","Win 95+","4","X"],["Trident","Internet Explorer 5.0","Win 95+","5","C"],["Trident","Internet Explorer 5.5","Win 95+","5.5","A"],["Trident","Internet Explorer 6","Win 98+","6","A"],["Trident","Internet Explorer 7","Win XP SP2+","7","A"]] }};
#"sEcho": 0,
#my $json = qq{{"error" : "username or password is wrong"}};
# print $cgi->header(-type => "application/json", -charset => "utf-8");
print $cgi->header( 'application/json' );
print $json;



but it seems something wrong. i can get table rendered. but it seems something wrong with it. i cant get do sorting or any other embeded datatables function.


Maybe i missed some facts , the author says
Quote:
The Perl script requires an extra parameter to be sent to it (rm), for which we can use fnServerData:
....blah
"sAjaxSource": "/cgi-bin/test/datatables/run.cgi",
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
....blah




i am losted. because i do not understand its real meaning.


That is all i have . but it is just a unsucessful testing .

Last edited by:

courierb: Nov 20, 2011, 5:55 PM
Subject Author Views Date
Thread JSON gotze 17514 Jul 24, 2010, 11:38 AM
Post Re: [gotze] JSON
Andy 17223 Jul 25, 2010, 1:42 AM
Thread Re: [gotze] JSON
tandat 17227 Jul 25, 2010, 2:49 AM
Thread Re: [tandat] JSON
gotze 17202 Jul 25, 2010, 7:49 AM
Thread Re: [gotze] JSON
gotze 17201 Jul 25, 2010, 11:58 AM
Thread Re: [gotze] JSON
gotze 17187 Jul 25, 2010, 12:27 PM
Thread Re: [gotze] JSON
Matthias70 17178 Jul 25, 2010, 12:36 PM
Thread Re: [Matthias70] JSON
gotze 17180 Jul 25, 2010, 12:57 PM
Thread Re: [gotze] JSON
Matthias70 17127 Jul 26, 2010, 9:27 AM
Post Re: [Matthias70] JSON
gotze 17113 Jul 26, 2010, 10:40 AM
Thread Re: [gotze] JSON
courierb 16544 Nov 11, 2011, 9:12 PM
Thread Re: [courierb] JSON
Andy 16557 Nov 13, 2011, 7:08 AM
Thread Re: [Andy] JSON
courierb 16519 Nov 19, 2011, 6:10 PM
Thread Re: [courierb] JSON
Andy 16539 Nov 20, 2011, 8:16 AM
Thread Re: [Andy] JSON
courierb 16524 Nov 20, 2011, 5:13 PM
Thread Re: [courierb] JSON
courierb 16508 Nov 20, 2011, 6:15 PM
Thread Re: [courierb] JSON
Andy 16516 Nov 21, 2011, 12:58 AM
Thread Re: [Andy] JSON
courierb 16460 Nov 22, 2011, 3:41 PM
Thread Re: [courierb] JSON
courierb 16461 Nov 22, 2011, 4:02 PM
Post Re: [courierb] JSON
Andy 16452 Nov 22, 2011, 11:58 PM
Post Re: [gotze] JSON
courierb 16542 Nov 20, 2011, 5:09 PM