[FUELCMS] Add a dropdown filter on item listing page

I m working on Fuelcms again for one of my long-term project, after spending some time to create a feature which you can’t find on the documentation , I have this idea to write a series of blog post on how I did some of the features by using Fuelcms . The admin on  Fuelcms forum is really helpful , I guess this is my way to contribute back to the  Fuelcms community.

This tutorial is suitable for Fuelcms user who have follow the documentation create advance module, but if you try to find a solution for this ,most likely you want to have this feature on your advance module, so I assume that you understand the basic concept and folder structure of advance module.

The item listing page on Fuelcms  is a very standard page, you can find it on almost every module, it provide a search filter, which allow you to search any field that you defined , but what if you want to have a drop down field to filter the result ?

Assume my module is call “Operation”.

1. First you need to edit  operation/config/operation_fuel_modules.php , the should be some config file for your module, add in this filters config. You just need to add in the filters config.

  • date_added is the field name , the field that you want to filter the listing.
  • default is for the default value, in this case the default value is set to ‘all’.
  • label is a tiny text that show beside your drop down filter.
  • type will be the field type, if you never set it as select, it will be a text box input.
2. Change the route by edit operation/config/operation_routes.php, the original routing might be redirect to fuel module folder ( FUEL_FOLDER.’/module’ ) but since we need to override it, we need to route it to a custom controller.
3. Create a new file in the controller folder , this will extend from the module controller and override the default setting. You should assign the drop down value in this controller , either by pre define value or pulling from some other model.
Once this 3 steps is done, you should be able to see the drop down select appear on your items listing page, you can now use this drop down field as part of your list filter , you can have an empty value option for display all items.

You may also like...