Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable paginating in default index view #28

Open
ishumilova opened this issue Feb 20, 2014 · 10 comments
Open

Enable paginating in default index view #28

ishumilova opened this issue Feb 20, 2014 · 10 comments

Comments

@ishumilova
Copy link

Hi!
I've got next problem: how can I enable sorting in a default index view?

@nebirhos
Copy link
Collaborator

nebirhos commented Mar 3, 2014

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!

@ishumilova
Copy link
Author

No, i mean that i need just a default index view without sorting =)

@nebirhos
Copy link
Collaborator

nebirhos commented Mar 7, 2014

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

@ishumilova
Copy link
Author

it's not what i want cause i want sortable tree view and plain table view)

@asecondwill
Copy link

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?

@zorab47
Copy link
Owner

zorab47 commented May 22, 2014

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

@asecondwill
Copy link

@zorab47 looks great, thanks. I get an undefined variable for presenter_config - how are you getting that to work?

@zorab47
Copy link
Owner

zorab47 commented May 22, 2014

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

@asecondwill
Copy link

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.

@zorab47
Copy link
Owner

zorab47 commented May 26, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants