theme_tableselect() cannot handle multiple columns under single header.

e.g. we have header "Operations" (with colspan=2), and two columns with edit and delete link.

Also, is there any reason why only the field keys specified in $header are called from $options? Unlike traversing of all options/rows in theme_table().

CommentFileSizeAuthor
#69 67-broken-manage-fields-table.png99.59 KBjparkinson1991
#66 d7-combined-365554.patch7.61 KBpol
#63 d7-combined-365554.patch6.97 KBpol
#62 d7-365554.patch2.18 KBpol
#61 d7-365554.patch3.07 KBpol
#47 365554-47-tests.patch3.54 KBstar-szr
#47 365554-47-combined.patch4.77 KBstar-szr
#45 drupal-365554-45-test.patch3.74 KBtim.plunkett
#45 drupal-365554-45-combined.patch4.98 KBtim.plunkett
#41 tableselect-colspan-365554-41.patch4.98 KBAugust1914
#41 interdiff.txt803 bytesAugust1914
#37 Screen shot 2012-05-01 at 3.20.28 PM.png38.1 KBdoublejosh
#33 tableselect-colspan-365554-33.patch4.98 KBdamiankloip
#32 tableselect-colspan-365554-32.patch4.89 KBdamiankloip
#29 tableselect-colspan-365554-29.patch4.82 KBno_commit_credit
#27 tableselect-colspan-365554-27-tests.patch3.56 KBadharris
#27 tableselect-colspan-365554-27-tests+fix.patch4.82 KBadharris
#25 tableselect-colspan-365554-25-tests.patch3.76 KBadharris
#25 tableselect-colspan-365554-25-tests+fix.patch5.02 KBadharris
#23 patch-result.jpg133.95 KBkristiaanvandeneynde
#17 365554-tableselect-colspan.patch1.26 KBkiphaas7
#17 365554-tableselect-colspan-D7.patch1.24 KBkiphaas7
#15 365554-tableselect-colspan.patch1.26 KBkiphaas7
#15 365554-tableselect-colspan-D7.patch1.24 KBkiphaas7
#13 365554-tableselect-group-columns_4.patch1.15 KBTheRec
#10 365554-tableselect-group-columns_3.patch1.14 KBcatch
#7 365554-tableselect-group-columns_3.patch1.14 KBTheRec
#5 365554-tableselect-group-columns_2.patch1.09 KBTheRec
tableselect-group-columns.patch938 bytesGurpartap Singh

Comments

Gurpartap Singh’s picture

With the patch we can do this way:

  $header = array(
    'item' => t('Item'),
    'operations' => array('data' => t('Operations'), 'colspan' => '2'),
  );

  //...

  $options[$id] = array(    
    'item' => $item_name, // first cell
    'operations' => array(
        $edit_link, // second cell
        $delete_link // third cell
    ),
  );
}

Status: Needs review » Needs work

The last submitted patch failed testing.

Gurpartap Singh’s picture

Status: Needs work » Needs review
cburschka’s picture

Status: Needs review » Needs work

The patch looks excellent; I can find no way to improve the code style or implementation. However, there should be a one-line comment above the is_array() check to explain what kind of special case is being processed. Make life easy for the ones who read this code. :)

(On an unrelated note, it seems iffy that theme_tableselect would take almost the same input as theme_table (header and rows/options), but theme_tableselect relying on keyed arrays while theme_table uses only ordered ones. theme_tableselect's approach looks superior; perhaps theme_table could eventually be patched to do it the same way.)

TheRec’s picture

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

Re-rolling.

It will surely be needed to achieve #301902: Allow more users to see the node admin page.

It is not really a good idea to apply something similar to theme_table(), as it is convenient sometimes to be able to add rows wherever you want without having to know which header it is related to, also (and mainly) theme_table() is not centered on table headers as it is possible to render tables without headers (not that it is a good idea, but it is a possibility).

Status: Needs review » Needs work

The last submitted patch failed testing.

TheRec’s picture

StatusFileSize
new1.14 KB

Obviously, everything is an array now in most cases, as the links are now passed as renderable arrays... so we must check if we are dealing with an array of data directly, or another sort of array (i.e. an array of table cells).

TheRec’s picture

Status: Needs work » Needs review
TheRec’s picture

Tests passed. I don't know why it didn't get up to the project server correctly.

catch’s picture

StatusFileSize
new1.14 KB

re-attaching for the bot, no changes.

catch’s picture

Priority: Normal » Critical

Also re-rolled for comment improvement. This is now blocking #301902: Allow more users to see the node admin page so bumping status.

moshe weitzman’s picture

looks good. please use -f switch on diff so we can see quickly what function you changed ... typo: determins

TheRec’s picture

Priority: Critical » Normal
StatusFileSize
new1.15 KB

This is not blocking 301902 as explained in #301902-156: Allow more users to see the node admin page, so we can switch it back to normal... but it does not change the fact that it would be useful to be able to have multiple rows for an header.

Corrected the typo.

MichaelCole’s picture

kiphaas7’s picture

Title: Multiple columns under single heading in tableselect table » Fix colspan in tableselect
Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
StatusFileSize
new1.24 KB
new1.26 KB

While working on a complicated tableselect in D7, I stumbled across a limitation in the tableselect element: it does not allow me to properly add cells in a row which spans multiple column cells.

Found this issue, and think my issue is related, since both are about issues with colspan and tableselect. However, mine is aimed at fixing colspan in row cells, while this issue was previously about fixing colspan in header rows.

With a small 2 line addition to the patch above (isset(cell row)), both issues can be squashed. Also, I think I fixed a small typo in a comment from the above patch ('An header' -> 'A header', h is not silent).

For my usecase (cell rows with colspan > 1), this patch fixes:

Case:

$header = array('1', '2', '3', '4');
$rows = array(
  array('data' => 'foo 1 and 2', 'colspan' => 2),
  array('data' => 'foo 3 and 4', 'colspan' => 2),
);

Result before: notices about undefined indexes (it expects 4 cells), and 4 cells per row, while only 2 were defined. Colspan attribute is applied correctly.
Result after: no notices, only 2 cells per row. Colspan attribute is applied correctly.

Changing title, bumping to D8, tagging as "needs backport to D7". Both D7 and D8 patches are attached.

kiphaas7’s picture

One more tag...

kiphaas7’s picture

... And I should upload identical patches...

xjm’s picture

We should be able to add an automated test for this. Also, before/after screenshots illustrating the bug would be helpful for reviewers.

kiphaas7’s picture

Think I have a vague idea how to test for this (compare results from theme_table and theme_tableselect), but no idea where to add this test. Any pointers?

kiphaas7’s picture

Status: Needs review » Needs work

setting back to 'needs work'. Still would appreciate some pointers where to correctly add tests for this.

xjm’s picture

Thanks @Kiphaas7! The test will probably go in core/modules/simpletest/tests/form.test, potentially using or adding to form_test.module in the same directory. If you search for "tableselect" in that file, you should be able to find the existing tests for the functionality; look for any that might be related to the theming/rendering of it.

xjm’s picture

Assigned: Gurpartap Singh » Unassigned
kristiaanvandeneynde’s picture

Issue tags: -Needs screenshots
StatusFileSize
new133.95 KB

Applied versus 7 and result looks good.

xjm’s picture

Thanks @kristiaanvandeneynde! So now we just need an automated test.

adharris’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.02 KB
new3.76 KB

These tests count the number of header cells/table cells in a rendered table. Should cover the cases of a colspaned header, a colspaned cell, and a colspaned cell under a colspaned header.

kristiaanvandeneynde’s picture

Patch could use some work, the comments are sometimes weird to read (e.g.: and two, and two) and there is duplicate code in there:

+  $items['form_test/tableselect/colspan'] = array(
+    'title' => 'Tableselect colspan test',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('_form_test_tableselect_colspan_form'),
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+  $items['form_test/tableselect/colspan'] = array(
+    'title' => 'Tableselect colspan test',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('_form_test_tableselect_colspan_form'),
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
adharris’s picture

Right. Great example of why you don't cut patches at 3am. These should have the duplicate code fixed. I cleaned up the comments a bit (switching things like 'column one' to 'the first column') to make things a bit clearer.

kristiaanvandeneynde’s picture

Looks much better now :)

no_commit_credit’s picture

StatusFileSize
new4.82 KB

Attached simply removes/replaces unneeded t() on the assertion message texts. Reference: http://drupal.org/simpletest-tutorial-drupal7#t

xjm’s picture

Status: Needs review » Reviewed & tested by the community

...And, the final test looks great. Thanks @adharris and @kristiaanvandeneynde!

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks! Committed/pushed to 8.x, moving to 7.x for backport.

damiankloip’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new4.89 KB

Here is backported patch for D7.

damiankloip’s picture

StatusFileSize
new4.98 KB

This patch instead please.

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, tableselect-colspan-365554-33.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review

#33: tableselect-colspan-365554-33.patch queued for re-testing.

HEAD was broken, so retesting.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, tableselect-colspan-365554-33.patch, failed testing.

doublejosh’s picture

StatusFileSize
new38.1 KB

Maybe the wrong place, but seems highly related...
There's are other issues with the column count and colspans. However, this may be due to the show/hide row weights feature.

kristiaanvandeneynde’s picture

@doublejosh
This seems like a separate issue to me.
Seeing as this one is already in D8 and about to be ported to D7, I suggest you open an entirely new issue on the matter.

xjm’s picture

August1914’s picture

Assigned: Unassigned » August1914
August1914’s picture

StatusFileSize
new803 bytes
new4.98 KB

The problem with 33 is that small variables are easily offended, and previous patch failed to apply the karma operator (++) to i. i (not me) just sat there in the for loop waiting for some sort of acknowledgement for the essential if modest role she was playing in the big scheme of things. Just shows what a little love will do ya.

August1914’s picture

Assigned: August1914 » Unassigned
August1914’s picture

Status: Needs work » Needs review
damiankloip’s picture

good spot August1914, was going to post a new patch for that. New patch looks good to me.

tim.plunkett’s picture

StatusFileSize
new4.98 KB
new3.74 KB

Reuploading as test-only and combined just to check the backported test.

xjm’s picture

Issue tags: +Needs manual testing

Can someone clarify whether #41 is an issue in D8?

star-szr’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing
StatusFileSize
new4.77 KB
new3.54 KB

There were no code changes between the patches in #29 and #45, so the $i++ issue was introduced in the original backport and not committed to 8.x. However the patch in #45 removes a newline from form.test where it shouldn't (again, introduced in the original backport), attached reroll resolves this.

I tested #45 in Chrome, Firefox, and Safari on OS X, and IE 6-9 by enabling form_test via drush and looking at form_test/tableselect/colspan. All passed, so marking RTBC after manual testing and patch review.

I also did manual testing in Chrome, Firefox, and Safari on OS X before and after the patch in #33 in an attempt to reproduce the behaviour shown in #37. I focused on OS X browsers because of the file name and format of the screenshot attached, I did test IE8 and IE9 as well though. I tested /admin/structure/types/manage/article/fields from a fresh install with and without overlay, resizing the browser window and dragging rows around.

kiphaas7’s picture

Just chiming in to say thanks for adding test coverage!

joachim’s picture

Issue tags: +Needs documentation

This will need documentation -- as it works rather differently than theme_table() does.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work

I agree with @joachim. Without documentation, I had trouble figuring out if this patch is an API change, API addition, or what - and that's important to know for Drupal 7. It also wasn't really obvious to me why we need to support this nested array thing, rather than relying on the caller to set 'colspan' properly everywhere (i.e., closer to what theme_table does)?... I'm not necessarily saying the patch is wrong, just that it's hard to tell.

There's also some minor code style issues (which appear to be present in the D7 backport only), e.g. this:

+ /**
+ * Test the tableselect #colspan functionality.

There is a space in front of the "/**" that shouldn't be there.

Setting back to needs work, but leaving this at Drupal 7 for now.

kiphaas7’s picture

David_Rothstein, joachim: I'd say this is an API bug. So this patch would make the API more consistent, thus could also be called an API addition. I'll try to summarize why in this post:

theme_table() always allowed for using the colspan attribute for table cells in both the header and body of the table. Primarly the following two cases can exist:

  1. A single header cell can represent a column with mutliple cells in each row (colspan > 1 on the header)
  2. Multiple header cells can represent multiple columns with just a single row cell in each row (colspan > 1 on body cells)

theme_tableselect, which could be seen as nothing more than a fancy wrapper around theme_table, does not handle colspan correctly, because of the following piece of code in theme_tableselect():

// As theme_table only maps header and row columns by order, create the
// correct order by iterating over the header fields.
foreach ($element['#header'] as $fieldname => $title) {
  $row['data'][] = $element['#options'][$key][$fieldname];
}

The nasty side effect of this loop is that it assumes the number of cells in the header are equal to the number of cells in an arbitrary table body row; which is a wrong assumption when using colspan.

http://drupal.org/node/365554#comment-2230026 fixed usecase #1,
http://drupal.org/node/365554#comment-5548108 fixed usecase #2,
http://drupal.org/node/365554#comment-5811412 introduced tests for D8,
http://drupal.org/node/365554#comment-6188690 introduced tests for D7.

All this patch does is make the loop mentioned above more forgiving for usecase #1 and #2. I can see why you'd want to use colspan explicitly in the loop for testing this, but I can't really see how that should work out...?

But yeah, the added code is a bit more cryptic, though that's what the inline code comments should fix.

kiphaas7’s picture

Visual representation of what this patch tries to enable for theme_tableselect. I still see theme_tableselect as a wrapper around theme_table, and theme_table was able to produce these results all along; the pre-processing code in theme_tableselect fails when it encounters a colspan-type structure.

http://jsfiddle.net/fcUjD/

ichokd’s picture

Status: Needs work » Needs review
Issue tags: -Needs documentation, -Needs backport to D7
yesct’s picture

#47: 365554-47-combined.patch queued for re-testing.

idebr queued 47: 365554-47-combined.patch for re-testing.

  • catch committed 9656e51 on 8.3.x
    Issue #365554 by TheRec, Kiphaas7, adharris, Gurpartap Singh: Fixed...

  • catch committed 9656e51 on 8.3.x
    Issue #365554 by TheRec, Kiphaas7, adharris, Gurpartap Singh: Fixed...

  • catch committed 9656e51 on 8.4.x
    Issue #365554 by TheRec, Kiphaas7, adharris, Gurpartap Singh: Fixed...

  • catch committed 9656e51 on 8.4.x
    Issue #365554 by TheRec, Kiphaas7, adharris, Gurpartap Singh: Fixed...
pol’s picture

Issue summary: View changes
StatusFileSize
new3.07 KB

Hi all,

Sorry to dig up old, very old topics, but we've encountered this issue while making a Drupal 7 theme.
I've managed to created a patch for Drupal 7, it's completely different from what I see here, let me know how it goes for you with it.

Basically the patch update the colspan attribute of <td>'s elements having the class tabledrag-has-colspan.
The colspan's value to set is computed by computing the length of <th>'s available in the table, except hidden ones and including colspan values.

pol’s picture

StatusFileSize
new2.18 KB

Patch updated.

pol’s picture

StatusFileSize
new6.97 KB

And here's the combined patch of #47 and #62.

The last submitted patch, 62: d7-365554.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 63: d7-combined-365554.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pol’s picture

Status: Needs work » Needs review
StatusFileSize
new7.61 KB

Updating the patch, replacing the .prop() jquery method with .attr().

Automatically adds the 'tabledrag-has-colspan' to body rows having colspan.

berliner’s picture

I didn't test this in depth, but the patch applies properly to Drupal core 7.65 and colspans are working in tableselect elements.

  • catch committed 9656e51 on 9.1.x
    Issue #365554 by TheRec, Kiphaas7, adharris, Gurpartap Singh: Fixed...
jparkinson1991’s picture

StatusFileSize
new99.59 KB

Patch in #66 breaks display of field management table for me.

Patch in #47 does not have this issue so using that.

avpaderno’s picture

The patch still applies to the 7.x branch.

quietone’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs review » Fixed

Adding credit for the commit to D8.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.