tableheader.js creates a second table which holds the sticky headers. To help ensure that the sticky headers are styled the same way as the original table's headers, the sticky-header table should have the same @class as the original table.

The attached patch patches tableheader.js so that the new table has the same classes as the original, except sticky-enabled, which is removed. sticky-header is added, as happens currently.

Issue fork drupal-590328

Command icon 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

liam morland’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new1.24 KB

Updated patch.

Liam Morland requested that failed test be re-tested.

aspilicious’s picture

Status: Needs review » Fixed

current code

      headerClone = $(headerClone)[0];

      // Store parent table.
      var table = $(this).parent('table')[0];
      headerClone.table = table;
      // Finish initializing header positioning.
      tracker(headerClone);
      // We hid the header to avoid it showing up erroneously on page load;
      // we need to unhide it now so that it will show up when expected.
      $(headerClone).children('thead').show();

      $(table).addClass('sticky-table');

Means sticky_table class is set :)!
Fixed!

liam morland’s picture

Status: Fixed » Needs review
StatusFileSize
new1.21 KB

The point if this patch is to ensure that the new table containing the sticky header has the same class as the original table, minus sticky-enabled, plus sticky-table. This is needed because some modules create sticky-enabled tables with other classes assigned. Without this patch, the sticky header tables won't match up with their tables since they have different CSS rules applied to them. I have attached my patch rerolled against the latest D7.

Status: Needs review » Needs work

The last submitted patch, tableheader-class.patch, failed testing.

aspilicious’s picture

Status: Needs work » Needs review

#6: tableheader-class.patch queued for re-testing.

liam morland’s picture

Version: 7.x-dev » 8.x-dev
StatusFileSize
new1.03 KB

Attached is a version of this patch rolled against the latest Drupal 8.

liam morland’s picture

StatusFileSize
new1.03 KB

Same patch again, renamed so that it will get tested.

liam morland’s picture

StatusFileSize
new1.05 KB

Updated patch rolled against latest D8.

liam morland’s picture

StatusFileSize
new1.05 KB

Sorry, typo. Updated patch rolled against latest D8.

Status: Needs review » Needs work

The last submitted patch, tableheader-class.patch, failed testing.

liam morland’s picture

Status: Needs work » Needs review

#11: tableheader-class.patch queued for re-testing.

liam morland’s picture

#12: tableheader-class.patch queued for re-testing.

liam morland’s picture

StatusFileSize
new1.05 KB

Updated patch rolled against latest D8.

liam morland’s picture

StatusFileSize
new1.25 KB

Reroll.

kiphaas7’s picture

+    // Copy classes from originalTable, remove undesired classes, and add
+    // sticky-header. Any other classes added to originalTable by modules will
+    // exists in stickyTable to ensure consistent styling.
+    this.$stickyTable.attr('class', this.originalTable.attr('class'));
+    this.$stickyTable.removeClass('sticky-enabled tableheader-processed sticky-table');
+    this.$stickyTable.addClass('sticky-header');

This looks fragile to me: suppose we're at a table with tabledrag enabled, or tableselect. They both add "-processed" classes, and both wouldn't be desired to be on the sticky table. let alone any contrib module.

Either we need a good whitelist (instead of blacklisting classes), or we need to pass the CSS classes set in php as a setting?

liam morland’s picture

Does it hurt if the sticky header has these extra classes? The idea of this patch is to ensure that the sticky header has the same classes so that it is sure to be styled the same.

droplet’s picture

@Kiphaas7,
can you explain more ? i don't get your meaning :)

@Liam,
No hurts I think and it should be.

droplet’s picture

Issue summary: View changes
Issue tags: +JavaScript
kiphaas7’s picture

I can't remember what my actual problem was there, but I think I was complaining about the blacklisting (=removing) of _just_ the classes mentioned in

this.$stickyTable.removeClass('sticky-enabled tableheader-processed sticky-table');

Contrib might do funky stuff to a table or table header as well, which might not be wanted on the sticky header. If the classes which are to be deleted are a javascript inline setting (passed in by php) contrib can overrule/extend it.

… Or contrib should write extra js to manually remove the class itself. However, that smells like a lot of event duplication in the javascript code. Basically I'd prefer if it was something like this

this.$stickyTable.removeClass(some.inline.setting.string.containing.all.the.classes);

liam morland’s picture

If I understand correctly, you would like modules to be able to add to the list of classes that are removed. That makes sense to me.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
adci_contributor’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.21 KB

Rerolled

zaporylie’s picture

Assigned: Unassigned » zaporylie
Status: Needs review » Needs work
Issue tags: +SprintWeekend2015

Because of missing `$` this patch doesn't work and gives errors in log console.

+++ b/core/misc/tableheader.js
@@ -158,6 +158,13 @@
+      this.$stickyTable.attr('class', this.originalTable.attr('class'));

Should be:

+++ b/core/misc/tableheader.js
@@ -158,6 +158,13 @@
+      this.$stickyTable.attr('class', this.$originalTable.attr('class'));

I will fix #25 and provide a patch in next comment.

zaporylie’s picture

Assigned: zaporylie » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.21 KB

...and here it is.

zaporylie’s picture

This is clean D8:

<table class="sticky-header" style="visibility: visible; position: fixed; top: 39px; left: 272.515625px; width: 1039px;">...</table>
<table class="views-table views-view-table sticky-enabled cols-7 responsive-enabled tableresponsive-processed table-select-processed tableheader-processed sticky-table">...</table>

and this is D8 + patch #27:

<table class="views-table views-view-table cols-7 responsive-enabled tableresponsive-processed table-select-processed sticky-header" style="visibility: hidden; position: fixed; top: 39px; left: 272.515625px; width: 1039px;">...</table>
<table class="views-table views-view-table sticky-enabled cols-7 responsive-enabled tableresponsive-processed table-select-processed tableheader-processed sticky-table">...</table>

I attached screenshots from chrome inspector as well.

wim leers’s picture

Issue tags: +markup, +CSS
FreekyMage’s picture

StatusFileSize
new1.08 KB

Reviewed, but changed so that the code is chained, which should give a small performance boost.

nod_’s picture

Status: Needs review » Needs work
+++ b/core/misc/tableheader.js
@@ -149,12 +149,18 @@
+        .attr('class', this.$originalTable.attr('class'))

Use addClass for consistency.

Also why do we do document.createElement now? we can just keep that and get rid of the addClass("sticky-header") line.

zaporylie’s picture

Status: Needs work » Needs review
StatusFileSize
new677 bytes
new1.12 KB

Here's a patch and interdiff.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Applies, sticky table inherits same classes as main table.

kiphaas7’s picture

And the comments in #18 - #23 are out of scope, or do these concerns no longer apply?

liam morland’s picture

Also why do we do document.createElement now?

I thought that would be neater and more clear, because it keeps all the class-related code together. As well, I suspect that it runs faster since jQuery no longer has to parse an HTML table tag with @class.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 32: 590328-32.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drintios’s picture

Assigned: Unassigned » drintios
drintios’s picture

StatusFileSize
new677 bytes

Did reroll of patch #32 against 8.2.x

drintios’s picture

Status: Needs work » Needs review

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

liam morland’s picture

Version: 8.3.x-dev » 8.4.x-dev

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xumepadismal’s picture

Re-rolled against 8.5.x

Status: Needs review » Needs work
droplet’s picture

Issue tags: +Needs JS tests

Add a test and let it go.

GrandmaGlassesRopeMan’s picture

StatusFileSize
new1.25 KB

- Reroll the patch from #45.

GrandmaGlassesRopeMan’s picture

Status: Needs work » Needs review

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

julia.klimovsky’s picture

StatusFileSize
new1.4 KB

Reroll the patch on 8.6.x

julia.klimovsky’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

avpaderno’s picture

Issue tags: -JavaScript, -Needs JS tests +JavaScript, +Needs JavaScript testing

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

berliner’s picture

Patch from #53 applies properly on 8.9.6 and works as advertised.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berliner’s picture

StatusFileSize
new1.43 KB

Patch updated to for 9.3.x-dev

berliner’s picture

StatusFileSize
new1.3 KB

Last patch had an indentation error. This one fixes it.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new143 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

gauravvvv’s picture

Status: Needs work » Needs review
StatusFileSize
new470 bytes

Patch #62 contains changes to tableheader.es6.js file. which is no longer part of 10.1.x
Re-rolled patch for 10.1.x. Please review

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This seems like something that can have a test case to show the issue.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cslevy’s picture

StatusFileSize
new547 bytes

I recreated the patch for Drupal 10.2.x

ajaypratapsingh’s picture

StatusFileSize
new547 bytes

I rerolled the patch for Drupal 11.x

dipakmdhrm’s picture

tableheader.js creates a second table which holds the sticky headers

I noticed that for a normal table, there's no duplicate sticky header. Header is made sticky using css.

But for a tableselect table, we have duplicate header.
In this case too, ideally we should be able to make the header sticky using css.

Why do we have duplicate header? Is this remnant from some old issue or do we still need this?

dipakmdhrm’s picture

Why do we have duplicate header? Is this remnant from some old issue or do we still need this?

To answer my own question, this was because IE11 didn't support `position: sticky`.
Now that Drupal >= 10 doesn't support IE11, we can use `position:sticky`.

It's already been done in https://www.drupal.org/project/drupal/issues/3362276 for some tables.

Let's do this for tableheader too.

dipakmdhrm’s picture

Status: Needs work » Closed (duplicate)