|
ListFilter
To filter list by a auto-submitted drop down list.
IntroductionIt is mostly used on some model that have a status. An option can be one status, or a combination of many statuses. The filtering field (or fields combination) can be associations or not, depending on your needs. There is another great plugin named activescaffoldlistfilters. It is more generic, while you only need to give the association names. InstallSame as BatchCreate UsageYou can add an option for one status, like config.list.add_filter "preparing", :status => "preparing" Or you can add an option for many statuses, like config.list.add_filter "processing", :status => ["placed", "processing"] You can also add an option on many fields, like config.list.add_filter "finished", :status => "processed", :verified => true If you don't specify a label, the filter name will be shown as the option text, but you can also give it a better label, like config.list.add_filter "preparing", :label => "Just Placed", :status => "preparing" If you want to show these options conditionally, e.g. hide some option to some users, you can add a before_filter to action list, like class OrdersController < ApplicationController
before_filter :add_filter_options, :only => :index
def add_filter_options
active_scaffold_config.list.add_filter "preparing", :status => "preparing"
active_scaffold_config.list.add_filter "processing", :status => ["placed", "processing"]
if current_user.has_role?('moderator')
active_scaffold_config.list.add_filter "finished", :status => "processed", :verified => true
end
end
endThere is a ester egg in this feature - the option you choose from the browser can be saved, try to find the usage by your own. Demohttp://demo.activescaffold.com.cn/orders BTW. The ActiveScaffold has been localized to Chinese, but the Order model and the filter options were kept in English. |
Sign in to add a comment