Currently, the "Header orientation" (meaning whether the first row, first column or both are headers) is a setting in the field formatter.
However, this isn't so much a display setting, as a setting about the semantics of the table data.
For example, technically, you could have the "Header orientation" be "First row" on the "Default" view mode, but "First column" on the "Teaser" view mode on the same content type. But for the same table data, that doesn't really make sense: the first row or first column are headers or values semantically, ie. it's just part of that specific table data.
Also, it'd be nice to have a tables of different "Header orientations" on different nodes of the same content type, as opposed to having to have a separate content type or field for tables with horizontal vs vertical headers.
Is this something that this project's maintainers would be open to?
I saw reference to doing this on the Drupal 8 version here:
#3019613-24: Move display related settings from manage fields to manage display and add options
What about on the Drupal 7 version?
The challenge for Drupal 7, of course, is the upgrade path, because there are lots of existing sites out there where this is only a field formatter setting, and maybe some of them don't want this configurable per entity. I'm not sure the best way to handle that, so just starting the discussion here first.
Thanks! :-)
Issue fork tablefield-3128030
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
lolandese commentedThanks for your interest still in the D7 version of this module. As you might have noticed there is no feature parity yet between the 7.3 and 8.2 version of the module. Oddly the D8 version lacks behind as it does not offer many new features that were introduced in the 7.x-3.x branch
Like you said, to be able to define the header orientation per individual table (just like the caption) does make more sense than currently being a field setting in a view mode. So, yes, a patch would be definitely welcomed. The upgrade path could iterate through all existing fields on all entities and set those to replicate the same current behaviour set in the default view mode for the bundle. We might as well mention that in the UPGRADE.txt and the in the release notes of a new stable version.
Ideally, we should pursue feature parity, so later that should be ported to D8 as well.
Also, as a more generic alternative solution consider #3019613-26: Move display related settings from manage fields to manage display and add options. It looks that the sandbox mentioned there for D7 lets you accomplish this differently. Look at the screenshot from the imaginary "About us" node page that offers a tab that makes you change the display settings for that node alone per field. You might want to test that first and report your findings.
Comment #3
dsnopekAlright, thanks!
Here's a patch that implements this.
It puts the "Header orientation" under "Change number of rows/columns" because that seemed like the most natural place for this:
And, if the user changes it and clicks "Rebuild Table" it'll update the styling on the form for the type of header. I had to switch this styling to use CSS classes on the field item, rather than conditionally loading certain CSS files. Whether or not the user can change this follows the same logic as if the user can change the number of rows or columns.
The default "Header orientation" for a field comes from the field's default value, which is also where the default row and column count come from.
So, for the update hook, it's moving the "Header orientation" from the field formatter on the default view mode, over to the default value on the field. Since this is used for the default of an field value that doesn't have a "Header orientation" set, this should be sufficient, we don't need to copy it on to every entity.
Please let me know what you think! Thanks :-)
Comment #4
lolandese commentedPatch applies cleanly:
Update executes smoothly:
On existing content (Edit):
Furthermore, the table display was originally set to both first to and column but was converted to first row only.
On edit save and adding new content all was working flawlessly as expected. Tested if a single multi-value table field could be displayed with the first table having both row and column as a header, the second only the first row and the third only the first column. It was all fine.
An awesome new feature. Looking forward to seeing this committed. BTW, I hope you don't mind I added you as a co-maintainer as you made commits to the TableField module also in the past and your D.O. profile shows an incredible +7K number of commits.
Comment #5
dsnopekThanks for the feedback!
Attached is a new patch that fixes these two problems.
Thanks, however, I don't really have much time to devote to maintaining yet another module, but I'll help out as I'm able. :-)
Comment #6
cboyden commentedOverall this is looking pretty good. The help text (if you're not hiding the first row) says "The first row will appear as the table header. Leave the first row blank if you do not need a header." Does this need to be adjusted now that there are multiple options for header orientation?
Comment #7
lolandese commentedPatch applies cleanly:
Update runs flawless:
[ok]
Both of the issues mentioned previously in comment #4 are now solved. That means there are no undefined errors on existing content and the settings as they were are ported correctly to both the field settings and on the content. I also checked if the old display option for the field was removed.
All fine.
About what to do if the first row is hidden, I checked the functionality. That is still there and works as expected. What becomes then the first row is then not displayed as a header anymore. That is identical to the previous behavior, so fine with me. But honestly, I forgot the exact use case of that option. I believe it is used in case one wants to see in the form edit what data to fill in, without making it visible in the node. A sort of column enabled field help description I guess. It would make sense to think it over but a new issue should be opened for that.
I suggest a small change to the name of the field group from:
Change number of rows/columns.
to simply:
Number of rows/columns and header orientation
Comment #9
lolandese commentedAbout the co-maintainership, just pick up things where you see fit. No obligations of any sort.
Many thanks for your awesome contribution.
Comment #10
lolandese commentedComment #11
alpe89 commentedThis is just what I was looking for :)
Will this be in the next 7.x release? Any idea of when this will be?
Comment #12
lolandese commentedYes, it will. I or any other maintainer will release a new stable release soon. Feel free to use the dev version meanwhile. Just in case, make a backup to be able to roll back, but it should be okay.
Comment #13
gresko8 commentedHere's a patch for 8.x-2.x version. Columns for 'row_header' and 'column_header' are added to field schema and rendered as checkboxes according to the tablefield formatter settings).
Comment #14
nicholassPatch #13 worked great for me. - Thanks!
Drupal core 8.9.13
TableField: 8.x-2.2
Comment #15
lolandese commentedThanks for this D8 port.
When reviewing it, try to explain what you tested more extensively as described in https://www.drupal.org/patch/review. Make sure to cover all scenarios, like using the vertical header, drag of rows, and import of a CSV. Ideally, we should extend the automated tests. It would be the only way to add new features to this module in a reliable way.
After thorough testing, feel free to also change the issue status to RTBC.
Comment #16
chri5tia commentedHello Team,
Upon testing the patch supplied in Comment 13, we see an integrity constraint violation (as well as mismatched entity definitions for the paragraph tablefield entity).
The integrity constraint violation happens after attempting to save any node which uses a tablefield paragraph entity, after applying the patch.
The patch updates the install file to include:
Something is problematic with default 0 and not null = true not applying correctly I think, not sure.
Comment #17
chri5tia commentedHere is a new patch that resolves the integrity constraint violation, moves the checkboxes and adds some unit tests, among a few other things.
Comment #18
chri5tia commentedRenamed.
Comment #19
coderdan commentedRe-rolled patch from #18 for version 2.3.
Comment #20
avpadernoComment #21
solantoast commentedRe-rolled patch from #19.
Comment #22
avpadernoComment #23
gresko8 commentedI tested the patch in #21 and it works well. Thanks!
The only thing that probably needs to be fixed is that we still have the checkboxes in field formatter settings. Since they are ignored because the actual settings stored on the entity are used, we should probably get rid of them.
Comment #24
lolandese commentedSee comment #23:
Comment #25
antonio_zoocha commentedI applied suggestion from #23 over patch from #21
Comment #26
antonio_zoocha commentedComment #27
liam morlandPlease use an issue fork and merge request.
Comment #29
agentrickardPatch no longer applies cleanly.
Comment #31
agentrickardThis is working fine on a clean install, but when applied to an existing Drupal 11 site, the `Use header` option still appears.
Investigating.
*UPDATE*
The use header option is a custom field that we were using.
Comment #32
agentrickardMR is ready for review.
Comment #33
liam morlandThere is one coding standards issue to fix.
Comment #34
agentrickardOdd, I would have expected the MR to not have a green check in that case.
Anyway, fixed.
Comment #35
liam morlandCoding standards issues do not prevent tests from being counted as passed.
Comment #36
agentrickardYeah,. I thought we could set that to strict. I suppose we can only skip them.
Comment #37
liam morlandIt can be configured so that coding standards issues create failures instead of warnings and then the overall will report a failure.
Comment #38
agentrickardAll that aside, this seems to be working as expected.
Comment #39
nicholassJust reporting been running the 41.diff for 11 months on prod and no issues, so going to mark as Reviewed.
Comment #40
nicholass