Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add sorted elements in the filter dropdown in activeadmin rails

I have a Post model, PostSource model. A PostSource has many posts, a post belong to one PostSource.

Using ActiveAdmin, in the Index action of the Post, I am displaying a filter of PostSource this way:

filter :post_source, label: 'Source'
filter :category, as: :select, collection: Category.order(:name).collect { |cat| [cat.name, cat.id] }

with the controller as:

controller do
  def scoped_collection
    end_of_association_chain.includes(:post_source)
  end
end

It displays the source, but does not display in a sorted order. How to sort the filter in this case?

I tried adding sortable, order on filter but it does not seem to work

like image 708
inquisitive Avatar asked Feb 11 '15 09:02

inquisitive


People also ask

How do you filter text in a drop down list?

Text Filters in Excel Drop Down List Filter To view the data more specifically, we can use text filters. To construct a drop-down box, choose all of the headings of the dataset. Then, go to the Data tab and select Filter. After that, click on the drop-down arrow, in the column of the text we want to filter.

How to extract data from a drop down list in Excel?

Create a Drop Down List 2. Excel Drop Down List Filter to Extract Data 2.1. Make a List of Unique Items 2.2. Put a Drop Down Filter to Show Unique Items 2.3. Use Helper Columns to Extract the Records

How to sort an array by number of albums in Salesforce?

1.Define another state variable for storing value of the sort property. By default, the bands array will be sorted by a number of albums. 2.Update the value of the sortType on select option change. 3.Add useEffect Hook, which will call sortArray function after the component renders and then every time on update of the sortType value.

How to search for items in a dropdown menu with CSS?

Learn how to search for items in a dropdown menu with CSS and JavaScript. Create a dropdown menu that appears when the user clicks on a button. <input type="text" placeholder="Search.." id="myInput" onkeyup="filterFunction ()"> Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element.


1 Answers

If you're trying to sort the first filter ('post_source'), you could just add a collection as you have in your second line, and sort within a block.

filter :post_source, label: 'Source', collection: proc { PostSource.order(:name) }

This syntax might be used as an alternative in the second example as well.

like image 194
LazyMonkey Avatar answered Sep 24 '22 22:09

LazyMonkey