Add/remove columns in a subpanel based on a value of "parent" module

Hi all!

There is a question I could not find answer to for more than some days
Appreciate your hints or directions very much!

Imagine an example (my real situation is too difficult to describe).

I have a parent module, for example “Country”, each record has some fields: currency, name, comments, report details etc.
There is a module “Services for a country”, describing details of one service we can do, including prices per unit, price per hour, and like that.
For each country there is a subpanel containing list of services for this country.

So far everything is fine: subpanel has columns “service name, service price, details”

UNFORTUNATELY, for some countries the general “price approach” is not OK.

For example, I have a country on the planet VENUS (I have a field in Country module saying that), and for this country I do not have price per unit, price per hour.

For this country I have just a textual description of some price: for VENUS the price is “200 kg of butter per year” and for another (say, JUPITER): “Price depends on GDP of Jupiterian economics, calculated on following formula …”.

(Please don’t laugh, I am serious).


For regular countries in subpanel “Services” I have to display regular columns of prices etc, with fixed width, as it is a number.
For irregular countries in that subpanel I have to HIDE regular columns and display the irregular price description.
(all these fields are created and defined for module “Services for country”, of course)

How can I hide/display particular columns in a subpanel based on a value in “parent” module?

I know about Widgets to be specified in file \custom\modules<child module>\metadata\subpanels, and the Widget has to be created.
The issue here is that the widget does NOT hide column: it just puts emptiness. The space for this column is still occupied.

Is there a way to remove a column from subpanel view during runtime, and to display another one?

Thanks in advance.
(Please dont tell Musk about Jupiter)

Nice and entertaining post to read! :slight_smile:

You can try with this technique

only instead of changing the format you can change the actual text displayed according to whatever condition you want. You can use the Beans to easily navigate your data.

If that is not enough, you can sub-class the List view and override its code. But I’ll explain more later only in case you need it.

Thank you for the reply!

I have already considered using ListView hooks.
And hooks for ListView is something I can do with closed eyes now (and I use it in other parts a lot).

The issue here is that the column needs to be added/removed in the subpanel, where the services for selected country are listed.
I.e. I open DetailView of a Country, and lower on the page, in the Subpanel, I see (modify) the list the services to deliver to these country.

List of services is different for each country (but the set of columns is the same for every type of country), and it is a relationship between parent (Country) and child (Services with cost) modules.

Unfortunately, as I understand - changing ListView does not affect the Subpanel View.

Probably, I missed something in ListView, but I have never managed to customize Subpanel view by changing anyting in ListView for the same module…

What can be done in this case? Or there is something in ListView I am just omitting?

Thanks in advance,

Well you can also override the Detail View class with your own custom code.

I don’t really know how, I never did it myself.

I found a post suggesting to see these files for examples: