1

Wondering if anybody has ever come up with a solution to this problem; my research tells me not. A bit convoluted explanation but hopefully you can understand...

I have a component which has both site and administrator views. Both have ordering so I can control the ordering of items returned in the list view for the frontend. Great, so "sports" view can list each individual "sport" in any order I set in the admin. Perfect.

In the single item "sport" view, data is returned to this view in the usual getItem() return $this->_item;. Of course, this is the entire table row.

Now, my issue is that we need to re-order the columns on a per-item ("sport") basis.

As an example, the object returned by getItem() is as below. Note, organisations and teams are subforms of "sports", so appear in separate tabs in the Joomla admin "Edit" view.

Sport Id #1:

Joomla\CMS\Object\CMSObject Object ( [_errors:protected] => Array ( ) [id] => [ordering] => [state] => [checked_out] => [checked_out_time] => [created_by] => [modified_by] => [sportname] => [invented] => [founders] => [description] => [organisations] => [teams] )

This is great, but for Sport ID #2, we want to return this object with the subforms in different order, like so:

Joomla\CMS\Object\CMSObject Object ( [_errors:protected] => Array ( ) [id] => [ordering] => [state] => [checked_out] => [checked_out_time] => [created_by] => [modified_by] => [sportname] => [description] => [founders] => [invented] => [teams] => [organisations] )

I have looked at adding an "order" integer field to each subform and then using this in the view to render the objects, but these cannot be made unique between subforms, creating room for user error in setting subforms to have the same integer value.

Has anyone come across this scenario and what are my options here?

If you managed to understand that, then thanks!

2 Answers 2

2

Here's my suggestion, assuming I've understood you correctly.

Use a separate tab "column ordering" in the edit form to allow the admin to specify the order in which the various columns appear. This will need to be a custom field obviously.

I would suggest storing it in the database as a json string, with the key being the column name and the value being the order (1, 2, 3, ..). So designate a new column in your component database table, or add this json string into an existing json field if you already have one.

You could try using the same UI approach as Joomla does to enable ordering. The code is in media/jui/js/sortablelist.js, and it's based on the jQuery Sortable I think. So you could try making your own version of the javascript for this custom field. The Joomla js code makes ajax calls to the server whenever a row is dragged to a new position in the ordering, so you might want to follow that approach.

1
  • Thanks @Robbie Jackson. That was the approach I was thinking of taking; it's kind of clunky from an admin user perspective, but I have not yet found any other 3rd party component which has done what I'm looking for. The difficulty is knowing that the columns (which represent each tab in the form) may or may not be empty, so will need to take that into account. Cheers for the HU on the sortablelist, that should come in handy. Cheers.
    – Grant G
    May 17, 2020 at 21:36
2

Seems odd to me as to why you need to change the display ordering between the different views - would that make for an inconsistent UX?

As it looks to be a localised customisation, I’d consider programming it into the template override for the view by looking at the ID for the item and then transpose the object array into a temporary array with the desired field ordering.

If you have a number of ordering groups required, you might need to store the ordering in a json field in a custom field somewhere.

Another method I’ve seen used is with a combination of Regular Labs extensions (www.regularlabs.com) including Artickes Anywhere and Sourcerer. You can then build layouts you can switch between based on fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.