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
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.
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
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.
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.
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.
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