Skip to content

08. Ordering (Sorting) records

JoomlaBoat edited this page Oct 23, 2023 · 7 revisions

To sort table records by one field:

  1. Enable "Allow Ordering" in the Field settings Optional tab.
  2. If you are using Custom Tables as a Menu Item: Go to the Settings tab and type the desired field name into the "Default sort by field" box. A user can overwrite this using the Order By the Select box. Use "Forced sort by field" to sort only by the desired field.
  3. If you are using Custom Tables as the Plugin: Type the field name into the 7th parameter.

Additional notes:

  • You can use the "_id" or "_published" words to order by a record ID or publish status accordingly.
  • If you are using a plugin to create custom tables, consult the plugin's documentation for specific instructions on how to sort table records.
  • To sort records in descending order add " desc" after the field name.

{customtablescatalog=Table Name,|Page Layout Name|,|Item Layout Name|,|Publish State|,|Filter|,|Sort by Field|,|Force Itemid|,|Limit|}

  • Table Name - Existing Custom Tables table.
  • Page Layout Name (Optional): Simple Catalog or Catalog Page layout to generate a catalog page.
  • Item Layout Name (Optional): Catalog Item layout used with Catalog Page only.
  • Publish State (Optional): Filter to show published or unpublished records or both (Options: showpublished, showunpublished, any)
  • Filter (Optional): 'Where clause' to extract specific records fulfilling a condition, and a limit clause for the number of records.
  • Sort by Field (Optional): Field name to sort by.
  • Force Itemid (Optional): Used to set parameters for edit form or apply permissions.
  • Limit (Optional): Limit the number of records.

Examples:

Insert records from the products table using the default layout:

{customtablescatalog=products}

Insert records from the products table as described in the List of Product layout, records must be published and the price more than 0, also sort records by name field:

{customtablescatalog=products,ListOfProduct,,published,price>0,name}

Insert records from the products table using the default layout and sort records by price field in descending order:

{customtablescatalog=products,,,,,price desc}

You can use Twig tags inside the parameter but enclose it with quotes. Insert published records from the countries table using the default layout where code field = 'pa', and limit the output to 5 records:

{customtablescatalog=countries,,,published,"code={{ 'p' ~ 'a'}}",,,5}