From 5e4a5b727ce47b1b01a0f7a8b3c1077efc703a3c Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Wed, 9 Sep 2015 22:22:31 +0200 Subject: [PATCH] add pagination --- app/controllers/concerns/data_table.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/data_table.rb b/app/controllers/concerns/data_table.rb index b9cc210..c8dacc8 100644 --- a/app/controllers/concerns/data_table.rb +++ b/app/controllers/concerns/data_table.rb @@ -4,7 +4,7 @@ module DataTable def apply_filter(user, params) params = sanitize_params(params) - selection_to_json(user, params[:draw], user.transactions) + selection_to_json user, params, user.transactions end private @@ -37,12 +37,11 @@ module DataTable end def selection_to_json(user, draw, selection) - selection = selection.to_a { draw: draw, recordsTotal: user.transactions.count, recordsFiltered: selection.count, - data: selection.map { |transaction| { + data: selection.offset(params[:start]).take(params[:length]).map { |transaction| { time: transaction.created_at, amount: transaction.signed_amount_for(user), peer: transaction.peer_of(user).try(:name),