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 .