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 20949 Jul 24, 2010, 11:38 AM
Post Re: [gotze] JSON
Andy 20609 Jul 25, 2010, 1:42 AM
Thread Re: [gotze] JSON
tandat 20616 Jul 25, 2010, 2:49 AM
Thread Re: [tandat] JSON
gotze 20593 Jul 25, 2010, 7:49 AM
Thread Re: [gotze] JSON
gotze 20591 Jul 25, 2010, 11:58 AM
Thread Re: [gotze] JSON
gotze 20573 Jul 25, 2010, 12:27 PM
Thread Re: [gotze] JSON
Matthias70 20567 Jul 25, 2010, 12:36 PM
Thread Re: [Matthias70] JSON
gotze 20572 Jul 25, 2010, 12:57 PM
Thread Re: [gotze] JSON
Matthias70 20516 Jul 26, 2010, 9:27 AM
Post Re: [Matthias70] JSON
gotze 20497 Jul 26, 2010, 10:40 AM
Thread Re: [gotze] JSON
courierb 19933 Nov 11, 2011, 9:12 PM
Thread Re: [courierb] JSON
Andy 19949 Nov 13, 2011, 7:08 AM
Thread Re: [Andy] JSON
courierb 19911 Nov 19, 2011, 6:10 PM
Thread Re: [courierb] JSON
Andy 19935 Nov 20, 2011, 8:16 AM
Thread Re: [Andy] JSON
courierb 19917 Nov 20, 2011, 5:13 PM
Thread Re: [courierb] JSON
courierb 19902 Nov 20, 2011, 6:15 PM
Thread Re: [courierb] JSON
Andy 19911 Nov 21, 2011, 12:58 AM
Thread Re: [Andy] JSON
courierb 19855 Nov 22, 2011, 3:41 PM
Thread Re: [courierb] JSON
courierb 19847 Nov 22, 2011, 4:02 PM
Post Re: [courierb] JSON
Andy 19835 Nov 22, 2011, 11:58 PM
Post Re: [gotze] JSON
courierb 19926 Nov 20, 2011, 5:09 PM