active_admin-sortable_tree
active_admin-sortable_tree copied to clipboard
Enable paginating in default index view
Hi! I've got next problem: how can I enable sorting in a default index view?
Hi! Do you mean the default table view with sorting? I didn't implement it since historically you have a lot of troubles doing drag'n'drop on a table, and also you can't have nested rows. Try to change sortable.js.coffee to use the index table and see what happens!
No, i mean that i need just a default index view without sorting =)
If you want the sortable view without the sortable js (why?) you can do a dirty hack and set
body.active_admin .index_content .ui-sortable > * {
pointer-events: none;
}
in your active_admin.css
it's not what i want cause i want sortable tree view and plain table view)
interesting question. You can easily have two index views, just declare them both in the admin.rb file, but how do we enable pagination for the table?
config.paginate = false
because the config is set to no pagination both views have no pagination. But we want the table to have pagination & the sortable view to not
index as: :table do
column :title
end
and
index as: :sortable do
etc..
end
did you find a good solution for this?
My solution is to use a before_filter
to reset the config options based on the presenter.
ActiveAdmin.register Category do
before_filter only: :index do
if presenter_config[:as] == :sortable
active_admin_config.paginate = false
active_admin_config.filters = false
end
end
end
@zorab47 looks great, thanks. I get an undefined variable for presenter_config - how are you getting that to work?
Ah, yes. I left out a few key things. Here is an updated example:
ActiveAdmin.register Category do
controller do
before_filter only: :index do
if sortable?
active_admin_config.paginate = false
active_admin_config.filters = false
end
end
def presenter_config
active_admin_config.get_page_presenter(action_name, params[:as]) || {}
end
def sortable?
presenter_config[:as] == :sortable
end
end
end
closer @zorab47 , but declaring the sortable tree at the top of the resource is overriding the pagination. it fetches all the items & no pagination buttons.
is there a way to make that conditional too?
btw, some really handy stuff above to know how to get at params, :as etc - thanks v much for sharing.
There are other :as
options, such as :table
or :blog
. Here when the presenter is the default table it will enable pagination and filters.
ActiveAdmin.register Category do
controller do
before_filter only: :index do
if table_presenter?
active_admin_config.paginate = true
active_admin_config.filters = true
end
end
def presenter_config
active_admin_config.get_page_presenter(action_name, params[:as]) || {}
end
def sortable_presenter?
presenter_config[:as] == :sortable
end
def table_presenter?
presenter_config[:as] == :table
end
end
end
Third time is the charm.