? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
6 Jan 2022

Summary of Changes

Decide for yourself which columns to display for any table. The button shows an updating count of how many columns are shown.

The choice of which column to display is stored in local storage so it is persistent for you in your browser for that site.
tables2

This should be added to every table and it can also be added by extension developers to their own table by just adding one line to the existing web assets.

// add the script
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('table.columns');

Testing Instructions

As there is new js you will need to run npm ci

This is a fork and continuation of work by @PhilETaylor @dgrammatiko @Fedik

aa0ac93 23 Dec 2021 avatar brianteeman lang
3afbf44 24 Dec 2021 avatar brianteeman minus
82dc916 24 Dec 2021 avatar brianteeman cs
1236207 6 Jan 2022 avatar brianteeman lint
c09474c 6 Jan 2022 avatar brianteeman lint
avatar brianteeman brianteeman - open - 6 Jan 2022
avatar brianteeman brianteeman - change - 6 Jan 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 Jan 2022
Category Administration com_associations com_banners com_categories com_contact com_content com_fields com_installer com_languages com_menus com_modules com_newsfeeds com_plugins com_tags com_templates com_users Language & Strings Repository NPM Change JavaScript
avatar brianteeman brianteeman - change - 6 Jan 2022
Labels Added: Language Change NPM Resource Changed ?
avatar brianteeman
brianteeman - comment - 6 Jan 2022

Yes thats out of scope

No I'm not moving it to the bottom. It makes no sense to hide it on the bottom of the second or third page scroll

avatar brianteeman
brianteeman - comment - 6 Jan 2022

your face must be really bruised the number of times that you smash your palm into it

avatar PhilETaylor
PhilETaylor - comment - 6 Jan 2022

Im sorry that you are not open to feedback and are so closed minded. Once again.

avatar PhilETaylor
PhilETaylor - comment - 6 Jan 2022

Also not seeing on User Notes or Users

avatar PhilETaylor
PhilETaylor - comment - 6 Jan 2022

maybe something to do with this:
Screenshot 2022-01-06 at 21 14 20

avatar Kostelano
Kostelano - comment - 6 Jan 2022

The first thing I noticed was that the function is not available everywhere, but in fact it makes sense to implement it on all tabular pages in the admin panel.

avatar brianteeman
brianteeman - comment - 6 Jan 2022

The js is producing an error when it can't select the text to use for the column header. This happens whenever the header is not a link because for those headers there is no span containing the text

avatar PhilETaylor
PhilETaylor - comment - 6 Jan 2022

This happens whenever the header is not a link because for those headers there is no span containing the text

https://github.com/joomla/joomla-cms/pull/32974/files#diff-5ff666260572eb6e2425429e4ffa0b6815227394932a44d65540f215d4aef8f2R94-R99

avatar brianteeman
brianteeman - comment - 6 Jan 2022

oops that got mixed in the js rewrite by @Fedik

@Fedik can you look at putting both of those back please

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

Also @Fedik please remove the $ from the variables, the jQuery era was many years ago a thing...

avatar PhilETaylor
PhilETaylor - comment - 6 Jan 2022

the jQuery era was many years ago a thing...

I feel attacked ;-) Im still writing very pretty jQuery code ;-)

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

I feel attacked ;-) Im still writing very pretty jQuery code ;-)

Ok, I can rephrase the jQuery to PHP, oops...

avatar Fedik
Fedik - comment - 7 Jan 2022

I will look

please remove the $ from the variables

Nope, and it nothing to do with jquery, it for code readability. I would suggest you to use it also.
$ used for variables that holds DOM element. If you see the code and see a variable with $ you know it some kind of DOM reference, holds one of document elements.
Example table and $table you can easily say that last one is more likely a table element (or an element that represent the table), while for first one you have to search code definition for it, so you losing a time here.

avatar dgrammatiko
dgrammatiko - comment - 7 Jan 2022

Dude just use tableElement instead the obnoxious $, if what you’re after is readability…

avatar brianteeman
brianteeman - comment - 7 Jan 2022

get a room to argue about $ ;)

avatar brianteeman
brianteeman - comment - 7 Jan 2022

The pages where the button did not appear have now been fixed - thanks @Fedik
Just need to make the titles non-selectable now

avatar brianteeman
brianteeman - comment - 8 Jan 2022

@Fedik @dgrammatiko if you could take a look at putting back the code that made the title checked by default and readonly that would be the final missing piece

avatar dgrammatiko
dgrammatiko - comment - 8 Jan 2022

@brianteeman it should be a simple conditional, what's the difference for the title elements ( I think they are using thead)?

avatar brianteeman
brianteeman - comment - 9 Jan 2022

It's the cell with scope row and th

avatar Fedik
Fedik - comment - 9 Jan 2022

@brianteeman I have made PR,
but the problem with that logic, it will not work for empty table.
It better to have a way to detect such columns by looking in a table header (extra data- attribute or something).

avatar brianteeman
brianteeman - comment - 9 Jan 2022

Thanks - I have merged the pr and am working on some tweaks. Instead of hiding the column I am going to make it checked and disabled

avatar brianteeman
brianteeman - comment - 9 Jan 2022

All issues resolved and ready for final tests - please

avatar Kostelano
Kostelano - comment - 9 Jan 2022

I have tested this item successfully on cb10bde

Cool feature. The headings are pinned, everything works well.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36591.

avatar Kostelano
Kostelano - comment - 9 Jan 2022

I have tested this item successfully on cb10bde

Cool feature. The headings are pinned, everything works well.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36591.

avatar Kostelano Kostelano - test_item - 9 Jan 2022 - Tested successfully
avatar PhilETaylor
PhilETaylor - comment - 9 Jan 2022

Is there a reason its not implemented in the following tables - surely if its going to be implemented on some, it should be on all.

  • Banners -> Clients
  • Banners -> Tracks
  • Users -> User Notes
  • Smart Search component ?
  • System -> Install -> Languages
  • System -> Clear Cache
  • System -> Database
  • System -> Manage -> Languages
  • System -> Manage -> Redirects
  • System -> Update Sites
  • System -> Mail Templates = Says 3 columns where there are 4

Outside the scope of this PR, would also be nice to implement something for tables in modules on a dashboard.

avatar PhilETaylor
PhilETaylor - comment - 9 Jan 2022

Are we happy that the storage keys have spaces and colons?

Screenshot 2022-01-09 at 15 09 50

Also if I manipulate the value stored, then on next page load I get a JS Error. Probably ok as I doubt hackers will be changing local storage values (unless there is a way to exploit this), but could be handled better.

TypeError: undefined is not an object (evaluating 'this.$headers[t].classList')

If accessing a key throws an exception like this it should be caught and the key removed from local storage, else the user will forever thing that Joomla is broken, and seek support, which will tell him to clean local storage, a feature not many users know about... when Joomla could just catch JS errors and remove the offending data.

avatar PhilETaylor
PhilETaylor - comment - 9 Jan 2022

Ok here is an issue.

A 3PD writes a component called com_mytags

My main view is a Tags view. My page title is correctly "Tags". I correctly implement tableoptions

My table view has columns in a different order to the Joomla Core Tags component, or a different number of columns. I get a Javascript error as table options tries to manipulate my columns using the stored preferences for the Joomla component com_tags stored in my browser.

solution is to prefix the key with something - maybe com_tags - to prevent collisions when used by other 3pd applications. 'com_tags' can be retrieved from the class list of the body tag, or the form action url for example.

avatar Fedik
Fedik - comment - 9 Jan 2022

If accessing a key throws an exception like this it should be caught and the key removed from local storage, else the user will forever thing that Joomla is broken

Makes sense,
enough just check if the index exists in toggleColumn(index, force) :

toggleColumn(index, force) {
  if (!this.$headers[index]) return;
...
...
avatar Fedik
Fedik - comment - 9 Jan 2022

Are we happy that the storage keys have spaces and colons?

As long as it works, but can change to anything.
The suffix for storage key is configurable, with <table data-name="foobar">

avatar brianteeman
brianteeman - comment - 9 Jan 2022

checklist as I work through them - thanks @PhilETaylor

  • Banners -> Clients
  • Banners -> Tracks
  • Users -> User Notes
  • Smart Search component ?
  • System -> Install -> Languages
  • System -> Clear Cache
  • System -> Database
  • System -> Manage -> Languages
  • System -> Manage -> Redirects
  • System -> Update Sites
avatar brianteeman
brianteeman - comment - 9 Jan 2022

System -> Mail Templates = Says 3 columns where there are 4

That's because the table is not correct and I will do a separate PR for that

avatar joomla-cms-bot joomla-cms-bot - change - 9 Jan 2022
Category Administration com_associations com_banners com_categories com_contact com_content com_fields com_installer com_languages com_menus com_modules com_newsfeeds com_plugins com_tags com_templates com_users Language & Strings Repository NPM Change JavaScript Administration com_associations com_banners com_cache com_categories com_contact com_content com_fields com_finder com_installer com_languages com_menus com_modules com_newsfeeds com_plugins
avatar brianteeman brianteeman - change - 9 Jan 2022
Labels Removed: Language Change NPM Resource Changed
e9fc22d 9 Jan 2022 avatar brianteeman oops
avatar Kostelano
Kostelano - comment - 15 Jan 2022

Downloaded and installed the PR package from 15.01. There is a problem. Did not check on all pages, but after installing the assembly with this PR, go to the Components - Tags page. Try to select 1-2-3 items (but not all). The action button in the toolbar will be inactive.

Once you have selected all the elements, it will become active.

There is no conflict in the console.

Screenshot_1

UPD
This problem is on all such pages.

UPD
Open "Columns" and click on the element. See...

Screenshot_2

avatar brianteeman
brianteeman - comment - 15 Jan 2022

Sadly I can confirm this.

@Fedik @dgrammatiko any ideas?

avatar dgrammatiko
dgrammatiko - comment - 15 Jan 2022
  • Option 1 (easy): the input check becomes unhidable as the title
  • Option 2: the buttons need to be aware of the changed state of the checkboxes (some kind of event)
avatar brianteeman
brianteeman - comment - 15 Jan 2022

I dont understand either ;)

avatar Fedik
Fedik - comment - 16 Jan 2022

That happens because buggy multiselect.js

avatar brianteeman
brianteeman - comment - 16 Jan 2022

The issue has been fixed - thanks @Fedik

avatar Kostelano
Kostelano - comment - 16 Jan 2022

This feature is not available on a page with blocked elements. There are only 2 columns, of course... But I'd rather be consistent in functionality.

avatar brianteeman
brianteeman - comment - 16 Jan 2022

Not sure I understand what you mean by "blocked elements".

avatar Kostelano
Kostelano - comment - 16 Jan 2022

Sorry. I mean this:

Screenshot_8

avatar brianteeman
brianteeman - comment - 16 Jan 2022

ok - I didnt enable it on a page like that as it would be pointless.

avatar Kostelano
Kostelano - comment - 16 Jan 2022

Ok, one more clarification on 2 pages - there is also no option to select columns.

Private messages
Search query analysis

avatar Quy
Quy - comment - 19 Jan 2022

Users > Manage > Permissions ?

avatar brianteeman
brianteeman - comment - 19 Jan 2022

@Quy it cannot work on that view because of the way the content can be filtered by component

avatar Quy
Quy - comment - 21 Jan 2022

Maybe add a down caret (v) to indicate that it is a dropdown.

avatar brianteeman
brianteeman - comment - 23 Jan 2022

Maybe add a down caret (v) to indicate that it is a dropdown.

Done.

Hope this makes it into 4.1 - it solves a lot of user issues

avatar Quy
Quy - comment - 26 Jan 2022

System -> Mail Templates = Says 3 columns where there are 4

That's because the table is not correct and I will do a separate PR for that

Can you please check as this is still an issue? Thanks.

avatar Quy
Quy - comment - 26 Jan 2022

Almost there.

mail-templates

avatar Quy
Quy - comment - 26 Jan 2022

Please add Workflows.

avatar brianteeman
brianteeman - comment - 26 Jan 2022

@Quy I dont know how to fix mail templates - sorry

avatar brianteeman
brianteeman - comment - 28 Jan 2022

Is there any chance of this making it into 4.1 please.

It's a much requested feature and it would be a shame for it to have to wait another 6 months.

Any improvements can be made during the 4.1 lifecycle

avatar Quy Quy - test_item - 28 Jan 2022 - Tested successfully
avatar Quy
Quy - comment - 28 Jan 2022

I have tested this item successfully on e9fc22d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36591.

avatar alikon alikon - test_item - 29 Jan 2022 - Tested successfully
avatar alikon
alikon - comment - 29 Jan 2022

I have tested this item successfully on e9fc22d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36591.

avatar alikon alikon - change - 29 Jan 2022
Status Pending Ready to Commit
avatar alikon
alikon - comment - 29 Jan 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36591.

avatar brianteeman brianteeman - change - 31 Jan 2022
Labels Added: ?
avatar roland-d roland-d - close - 1 Feb 2022
avatar roland-d roland-d - merge - 1 Feb 2022
avatar roland-d roland-d - change - 1 Feb 2022
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2022-02-01 20:23:50
Closed_By roland-d
Labels Added: ?
Removed: ?
avatar roland-d
roland-d - comment - 1 Feb 2022

@brianteeman As Joomla 4.1 is in feature freeze Benjamin asked me to merge it for 4.2. I agree this is a great feature, so have it merged for 4.2.

Thanks everybody for working on this.

avatar brianteeman
brianteeman - comment - 1 Feb 2022

thanks for merging - shame people will have to wait :(

avatar Kostelano
Kostelano - comment - 11 Feb 2022

Please add a language tag to the PR

avatar joeforjoomla
joeforjoomla - comment - 15 Feb 2022

This script is too much generic if used for third-party extensions. It searches for all tables in a page throwing a JS error if there is no head section or applying the hide columns control to all found tables even if undesired.
It's a pity it can't be used only for the main or specific table in backend. It would be great an addition to exclude or include only tables that really need it.
image

avatar Fedik
Fedik - comment - 15 Feb 2022

Well, that was expected. But people wanted like that.
You better open an issue with some "test case" description. If you like.

avatar brianteeman
brianteeman - comment - 15 Feb 2022

a table without a head section is invalid so not going to apologise if it doesnt work

avatar brianteeman
brianteeman - comment - 16 Feb 2022

It would be great an addition to exclude or include only tables that really need it.

I dont understand - you have to add it to your component to use it. its not automatic

avatar joeforjoomla
joeforjoomla - comment - 16 Feb 2022

It would be great an addition to exclude or include only tables that really need it.

I dont understand - you have to add it to your component to use it. its not automatic

@brianteeman of course i know.

The problem now, is that this code should skip unnamed tables, but actually it doesn't do this because if a table has no name it fallbacks to the header title:

const tableName = $table.dataset.name ? $table.dataset.name : document.querySelector('.page-title').textContent.trim().replace(/[^a-z0-9]/gi, '-').toLowerCase(); // Skip unnamed table

    if (!tableName) {
      return;
    }

As a consequence if there are let's say 3 tables in the backend interface of a component but not all 3 tables used for columns to be hidden, then this feature will apply to all of them.
Furthermore, if a table has an empty <head></head> without any <tr>, than you have a the javascript error because of this line of code looking at the 'children' attribute of null:

this.$headers = [].slice.call($table.querySelector('thead tr').children);
Then it should be the case to fix the 'children' code to avoid a JS error, or to introduce an option for a configurable JS selector to include or exclude only certain tables.

I hope to have well explained.

avatar brianteeman
brianteeman - comment - 16 Feb 2022

Two choices

  1. Don't implement the script in your component
  2. Submit a pull request with the required changes
avatar impressionestudio
impressionestudio - comment - 17 Aug 2022

Very useful option but...

Why the new dropdown list button for the columns is placed in a new line and not in the same row and after the dropdown list button for the list limit?

As, for example, the list limit button affects the table, also does this new button for the columns of the table. So they should placed together.

There is space for them to fit in one row and if the left menu is closed then there is more space. I think we need to stop pushing the table too much down.

Also the other filters have a specific ID or class e.g. "list_limit", "list_fullordering". Why the new button for the columns doesn't have?

avatar HSorgYves
HSorgYves - comment - 7 Sep 2022

d-xxl-table-cell, d-sm-table-cell and d-xs-table-cell aren't removed by the JavaScript. Can you please adjust the JS?

Add a Comment

Login with GitHub to post a comment