Action List to json : it’s possible to paginate ?

14 views
Skip to first unread message

Gloufy

unread,
Aug 12, 2019, 4:57:21 PM8/12/19
to ActiveScaffold : Ruby on Rails Gem
Hi,

It’s possible to get a json from a list and paginate like when i get it in html page=1 etc?
Thank you for your help

Gloufy

Sergio Cambra

unread,
Aug 13, 2019, 10:39:28 AM8/13/19
to actives...@googlegroups.com
Hi

It's not possible by default, but you can override find_page_options in your
controller.

def find_page_options
options = {
:sorting => active_scaffold_config.list.user.sorting,
:count_includes => active_scaffold_config.list.user.count_includes
}

paginate = params[:format].nil? ? accepts?(:html, :js) : %w[html
js].include?(params[:format])
options[:pagination] = active_scaffold_config.list.pagination if paginate
if options[:pagination]
options[:per_page] = active_scaffold_config.list.user.per_page
options[:page] = active_scaffold_config.list.user.page
end

if active_scaffold_config.list.auto_select_columns
auto_select_columns = list_columns +
[active_scaffold_config.columns[active_scaffold_config.model.primary_key]]
options[:select] = auto_select_columns.map { |c|
quoted_select_columns(c.select_columns) }.compact.flatten
end

options
end

This line is disabling paginate for other formats than html or js:

paginate = params[:format].nil? ? accepts?(:html, :js) : %w[html js].include?
(params[:format])

You can call super and add lines below that line:

def find_page_options
options = super

unless options[:pagination]
options[:pagination] = active_scaffold_config.list.pagination
if options[:pagination]
options[:per_page] = active_scaffold_config.list.user.per_page
options[:page] = active_scaffold_config.list.user.page
end
end

options
end

I have been thinking for a while in changing this, and add a config option, so
pagination can be optionally enabled for other formats than html and js.

Regards,
Sergio


Gloufy

unread,
Aug 13, 2019, 1:35:15 PM8/13/19
to ActiveScaffold : Ruby on Rails Gem
thank you a lot it's working !!!

Printer Setup

unread,
Aug 20, 2019, 10:26:24 AM8/20/19
to ActiveScaffold : Ruby on Rails Gem
Thanks for sharing.
Reply all
Reply to author
Forward
0 new messages