I'm trying to setup the smart_listing gem in my app. Where and how can I configure the default per page number of pagination results. In the docs of smart_listing is mentioned that it uses kaminari.
If you don't already have a config/initializers/kaminari_config.rb
file, run Kaminari's config generator:
bundle exec rails generate kaminari:config
This will create config/initializers/kaminari_config.rb
with the default content:
Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
Simply uncomment and edit the configuration options you are interested in changing.
Update:
SmartListing provides it's own configuration options for pagination in config/initializers/smart_listing.rb
:
SmartListing.configure do |config|
config.global_options({
#:param_names => { # param names
#:page => :page,
#:per_page => :per_page,
#:sort => :sort,
#},
#:array => false, # controls whether smart list should be using arrays or AR collections
#:max_count => nil, # limit number of rows
#:unlimited_per_page => false, # allow infinite page size
#:paginate => true, # allow pagination
#:memorize_per_page => false, # save per page settings in the cookie
#:page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array
#:kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options
})
config.constants :classes, {
#:main => "smart-listing",
#:editable => "editable",
#:content => "content",
#:loading => "loading",
#:status => "smart-listing-status",
#:item_actions => "actions",
#:new_item_placeholder => "new-item-placeholder",
#:new_item_action => "new-item-action",
#:new_item_button => "btn",
#:hidden => "hidden",
#:autoselect => "autoselect",
#:callback => "callback",
#:pagination_per_page => "pagination-per-page text-center",
#:pagination_count => "count",
#:inline_editing => "info",
#:no_records => "no-records",
#:limit => "smart-listing-limit",
#:limit_alert => "smart-listing-limit-alert",
#:controls => "smart-listing-controls",
#:controls_reset => "reset",
#:filtering => "filter",
#:filtering_search => "glyphicon-search",
#:filtering_cancel => "glyphicon-remove",
#:filtering_disabled => "disabled",
#:sortable => "sortable",
#:icon_new => "glyphicon glyphicon-plus",
#:icon_edit => "glyphicon glyphicon-pencil",
#:icon_trash => "glyphicon glyphicon-trash",
#:icon_inactive => "glyphicon glyphicon-circle",
#:icon_show => "glyphicon glyphicon-share-alt",
#:icon_sort_none => "glyphicon glyphicon-resize-vertical",
#:icon_sort_up => "glyphicon glyphicon-chevron-up",
#:icon_sort_down => "glyphicon glyphicon-chevron-down",
}
config.constants :data_attributes, {
#:main => "smart-listing",
#:confirmation => "confirmation",
#:id => "id",
#:href => "href",
#:callback_href => "callback-href",
#:max_count => "max-count",
#:inline_edit_backup => "smart-listing-edit-backup",
#:params => "params",
#:observed => "observed",
#:href => "href",
#:autoshow => "autoshow",
#:popover => "slpopover",
}
config.constants :selectors, {
#:item_action_destroy => "a.destroy",
#:edit_cancel => "button.cancel",
#:row => "tr",
#:head => "thead",
#:filtering_icon => "i"
}
end
Uncomment the page_sizes line and replace DEFAULT_PAGE_SIZES with an array like [10, 20, 50, 100]
No need to comment out page_sizes
in initializers/smart_listing.rb
.
You can just define per_page
value in controller, eg:
users_scope = User.all.includes(:bio)
users_scope = users_scope.like(params[:filter]) if params[:filter]
@users = smart_listing_create :users, users_scope, partial: "users/list", page_sizes: [5, 7, 13, 26]
smart_listing v1.1.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With