From ac9d981aa9e59f1150c1b616c2b3e2cc5dff0682 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 8 Mar 2013 10:32:23 +0100 Subject: [PATCH] Pagination, Template enhancements for datatables - made template more flexible - process pagination in reseller/ajax - use datatables on /reseller - add edit/delete buttons to template --- lib/NGCP/Panel/Controller/Reseller.pm | 13 ++++++++++--- share/templates/helpers/datatables.tt | 14 +++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Reseller.pm b/lib/NGCP/Panel/Controller/Reseller.pm index 8cc3d804ac..6c0f7cd120 100644 --- a/lib/NGCP/Panel/Controller/Reseller.pm +++ b/lib/NGCP/Panel/Controller/Reseller.pm @@ -32,7 +32,7 @@ sub list :Chained('/') :PathPart('reseller') :CaptureArgs(0) { {id => 6, 'contract.id' => 6, name => 'reseller 6', status => 'terminated'}, ]; $c->stash(resellers => $resellers); - $c->stash(template => 'reseller/list.tt'); + $c->stash(template => 'reseller/listdt.tt'); NGCP::Panel::Utils::check_redirect_chain(c => $c); } @@ -161,10 +161,17 @@ sub ajax :Chained('list') :PathPart('ajax') :Args(0) { $row->{status}]; } } + my $totalRecords = scalar(@$aaData); + #Pagination + if($iDisplayStart || $iDisplayLength ) { + my $endIndex = $iDisplayLength+$iDisplayStart-1; + $endIndex = $#$aaData if $endIndex > $#$aaData; + @$aaData = @$aaData[$iDisplayStart .. $endIndex]; + } $c->stash(aaData => $aaData, - iTotalRecords => scalar(@$aaData), - iTotalDisplayRecords => scalar(@$aaData)); + iTotalRecords => $totalRecords, + iTotalDisplayRecords => $totalRecords); $c->detach( $c->view("JSON") ); } diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 484232df76..3272acfeb7 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -10,12 +10,20 @@ $(document).ready(function() { "bLengthChange": false, "bSort": false, "bInfo": true, - "sAjaxSource": "ajax/", + "iDisplayLength": 5, + "sAjaxSource": "[% c.uri_for( c.controller.action_for('ajax') ) %]", "aoColumns": [ [% FOREACH f IN helper.column_fields -%] { "sName": "[% f %]" }, [% END -%] + { "mRender": function ( data, type, full ) { + return 'Edit'+ + ' Delete'; + }, + "mData": null, + "sWidth": "132px" + } ], } ); @@ -40,14 +48,14 @@ $(document).ready(function() { [% FOREACH t IN helper.column_titles -%] [% t %] [% END -%] + [% # one for actions -%] + - [% FOREACH set IN helper.data -%] Loading - [% END -%]