Problem/Motivation
Due to the code for responsive tables that adds the header content as an attribute to all cells, sortable tables break in the front-end.
This is due to the fact that sortable tables have Link objects as their header content and the Attribute rendering class can't handle them.
Steps to reproduce
Create a sortable table in the front-end.
Proposed resolution
Add a check that converts Link objects to strings when adding them as attributes.
Issue fork rocketship_theme_generator-3228666
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rembrandx commented@L_VanDamme: I'm not entirely sure what you mean with converting the Link objects to strings. If you've already fixed it somewhere, I would appreciate a patch, MR or a code sample.
Comment #3
rembrandx commentedOr at least point me to the file where you think this code is located.
Comment #4
rembrandx commentedI'm guessing you mean that this bit of code in the .theme file should check the header 'content' for links and extract the text instead?
Will keep this issue open until we've properly reproduced & tested this. At the moment, I'm not finding any use cases (or implementations) of this kind of sortable tables in the front-end, so I'm not sure how/where to test this.
Comment #5
rembrandx commentedAfter some deliberation and testing with a table-formatted view, I believe the best solution for this use case (sortable tables or any links on th's), is NOT to use the 'reformatted' type of responsive table but 'scroll'. From a UI point of view, reformatting the table makes no sense if your because the behavior relies on the th's always being there on top.
There are 2 types available: scrolling and reformatted. You can pick either one to force onto tables (if generated outside of CKE) by applying the 'responsive' attribute and passing a class via a preprocess hook.
This is an example of how to set it for a view table.
If you're targetting a table directly, it's possible you need to use
$variables['table']['#responsive']and$variables['table']['#attributes']for getting to the classes.(eg. the preprocess_office_hours_table function in the .theme file can be used as a starting point)
Regardless of this:
Comment #7
rembrandx commentedSome of my thoughts on the use cases of 'reformatted' vs 'scrolling' tables:
Picking one of the 2 depends on what kind of data the table needs to handle and its overall purpose for the user/visitor. Most likely, as soon as its purpose is ‘display a set of data’, scrolling tables is the sensible way to display it.
Reformatted tables only make sense (in my opinion) for very specific use cases, such as a product basket in a webshop, or perhaps a small table with product properties.
It’s just that a case which requires reformatted tables will not likely overlap with a case where the table needs actions in its header (eg. those links for sorting).
Comment #10
rembrandx commentedGot the example (a custom table in a form), added the fix