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

Add possibility to sort by group #52

Open
sasselin opened this issue Sep 21, 2015 · 1 comment
Open

Add possibility to sort by group #52

sasselin opened this issue Sep 21, 2015 · 1 comment

Comments

@sasselin
Copy link

Example:

Category #1

  • Element 1 to sort
  • Element 2 to sort

Category #2

  • Element 1 to sort
  • Element 2 to sort
@ouelletv
Copy link

Here is a possible solution i came up with :

In nestable_helper.rb

module RailsAdmin
  module NestableHelper
    RailsAdmin::ApplicationHelper.class_eval do
      def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # perf matters here (no action view trickery)
        actions = actions(parent, abstract_model, object).select { |a| a.http_methods.include?(:get) }
        actions.collect do |action|
          wording = wording_for(:menu, action)
          %(
            <li title="#{wording if only_icon}" rel="#{'tooltip' if only_icon}" class="icon #{action.key}_#{parent}_link #{'active' if current_action?(action)}">
              <a class="#{action.pjax? ? 'pjax' : ''}" href="#{url_for(action: action.action_name, controller: 'rails_admin/main', model_name: abstract_model.try(:to_param), id: (object.try(:persisted?) && object.try(:id) || nil), query: (action.key == :nestable) ? params[:query] : nil)}">
                <i class="#{action.link_icon}"></i>
                <span#{only_icon ? " style='display:none'" : ''}>#{wording}</span>
              </a>
            </li>
          )
        end.join.html_safe
      end
    end
  end
end

This little snippet allows you to pass along the query param in the url to the orderable list view. Then, you could just use the built in rails_admin filter to scope your list and order the filtered results.

I was thinking about doing a merge request about this. Tell me what you guys think.

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

No branches or pull requests

2 participants