Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

016. Adding Ordering and Filter

Astrid edited this page Jan 29, 2020 · 8 revisions

Adding Ordering and Filter

In this chapter we will ...

Now, we want to create filters and search tools.

In Joomla 4, there are like in Joomla 3 some view filters and search tools that allow you to limit the items shown. For instance, only showing items where the status is published.

Besides the

  • status filter, we usually expect to see
  • search in title or content,
  • sort table by, and
  • ordering.

Foo Manager Administration Search Tools

Newly created or Modified files

Newly created files

administrator/components/com_foos/forms/filter_foos.xml

administrator/components/com_foos/sql/updates/mysql/1.16.0.sql

Modified files

changelog.xml

foo_update.xml

administrator/components/com_foos/Model/FooModel.php

administrator/components/com_foos/Model/FoosModel.php

administrator/components/com_foos/View/Foos/HtmlView.php

administrator/components/com_foos/foos.xml

administrator/components/com_foos/forms/foo.xml

administrator/components/com_foos/language/en-GB/en-GB.com_foos.ini

administrator/components/com_foos/tmpl/foos/default.php

administrator/components/com_foos/tmpl/foos/modal.php

All changes at a glance

Click here to see all changes compared to the last chapter.

More detailed explanations

File Structure

Newly created files

We will start off by adding a template that contains all necessary fields.

administrator/components/com_foos/forms/filter_foos.xml

We can now save a custom order. For this we need an entry in the database. The file administrator/components/com_foos/sql/updates/mysql/1.16.0.sql ensures that the column is created during the update. We don't need to do much more. Everything else is done by Joomla! for us

administrator/components/com_foos/sql/updates/mysql/1.16.0.sql

Modified files

And as usual: We need to modify our installation XML file, the update server and the change log to include the new version.

changelog.xml

foo_update.xml

administrator/components/com_foos/forms/foo.xml

We have adjusted the database. We adapt the model so that the order is saved here. Otherwise it doesn't actually work. Moreover we need to modify the model so that it filters the results shown based on the value of the filter.

administrator/components/com_foos/Model/FooModel.php

administrator/components/com_foos/Model/FoosModel.php

administrator/components/com_foos/View/Foos/HtmlView.php

administrator/components/com_foos/foos.xml

administrator/components/com_foos/language/en-GB/en-GB.com_foos.ini

administrator/components/com_foos/tmpl/foos/default.php

administrator/components/com_foos/tmpl/foos/modal.php

Example in Joomla 4

Side Note

Test your component

Now you can zip all files and install them via Joomla Extension Manager. After that you can see a link to your component in the left side menu. Clicking on this link will open the basic backend view.

Concluding Remark

Now we have . Up to now we have no . We are going to work on this in the next chapter.

Overview of all files