From f5afd4911b4b34c4ec85fbe2941e8e59872085aa Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 8 Mar 2013 14:29:34 +0100 Subject: [PATCH] use serverside sorting in datatables --- lib/NGCP/Panel/Controller/Root.pm | 13 +++++++++++++ share/templates/helpers/datatables.tt | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index ab430e39da..fab8dadeb6 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -101,16 +101,29 @@ sub ajax_process :Private { my $sSearch = $c->request->params->{sSearch} // ""; #/ my $iDisplayStart = $c->request->params->{iDisplayStart}; my $iDisplayLength = $c->request->params->{iDisplayLength}; + my $iSortCol_0 = $c->request->params->{iSortCol_0}; + my $sSortDir_0 = $c->request->params->{sSortDir_0}; #parse $data into $aaData my $aaData = []; for my $row (@$data) { my @aaRow = @$row{@$columns}; + #my %aaRow = %$row; #in case of using mData if (grep /$sSearch/, @aaRow[@$searchable]) { push @$aaData, \@aaRow; } } + #Sorting + if(defined($iSortCol_0) && defined($sSortDir_0)) { + if($sSortDir_0 eq "asc") { + @$aaData = sort {$a->[$iSortCol_0] cmp + $b->[$iSortCol_0]} @$aaData; + } else { + @$aaData = sort {$b->[$iSortCol_0] cmp + $a->[$iSortCol_0]} @$aaData; + } + } my $totalRecords = scalar(@$aaData); #Pagination if($iDisplayStart || $iDisplayLength ) { diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 3272acfeb7..8ac40e77da 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -8,7 +8,7 @@ $(document).ready(function() { "bServerSide": true, "bPaginate": true, "bLengthChange": false, - "bSort": false, + "bSort": true, "bInfo": true, "iDisplayLength": 5, "sAjaxSource": "[% c.uri_for( c.controller.action_for('ajax') ) %]", @@ -22,7 +22,8 @@ $(document).ready(function() { ' Delete'; }, "mData": null, - "sWidth": "132px" + "sWidth": "132px", + "bSortable": false } ], } );