Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
there's a bug with tablesort, the colspan attribute and the "active-row-highlighting"
Example:
Some cols in my tableheader have the colspan attribute. Tablesort is enabled.
When I sort the table, tablesort sets only one row to class "active", not all rows which are included in the colspan range.
Here is some example code.
Example Code
/**
* Buggy tablesort when using colspan
*/
function example_table() {
$sql = "SELECT * FROM {node}";
$header = array(
array('data' => t('Title'), 'field' => 'title', 'colspan' => '2')
, ''
, array('data' => t('Types'),'field' => 'type', 'colspan' => '3')
, ''
, ''
);
$sql .= tablesort_sql($header);
$result = db_query(db_rewrite_sql($sql));
$rows = array();
while ($node = db_fetch_object($result)) {
$row = array();
$row[] = 'foo';
$row[] = $node->title;
$row[] = 'bar';
$row[] = $node->type;
$row[] = 'foobar';
$row[] = 'barfoo';
$rows[] = $row;
}
$output = theme('table', $header, $rows);
return $output;
}
I think i can fix the tablesort code, but I am not very fimiliar with the drupal coding guidelines!
I hope someone will fix this soon! :)
Ty,
axe312
Ps.: I hope my english is understandable ;)
Comment | File | Size | Author |
---|---|---|---|
#48 | 838096-48--tablesort_active_class.patch | 8.08 KB | drunken monkey |
#48 | 838096-48--tablesort_active_class--tests_only.patch | 4.96 KB | drunken monkey |
Comments
Comment #1
drunken monkeyProblem exists in HEAD, too. Attached is a screenshot (from 7.x-dev).
Probably related to #557040: theme_table() adds 'active' class for the wrong columns when using rowspan (insofar, that we should be able to fix both at the same time).
Comment #2
drunken monkeyPatch attached.
Fixes problems with all sorts of colspan and rowspan weirdness, except one special case were I think even the HTML result would be unspecified – and you'd have to be pretty insane to even try it.
And because I'm a good monkey, there are even tests for it. Rejoice! (The first patch contains only the tests and is there to demonstrate that it previously failed horribly. (Here's to hoping the second one doesn't fail equally horribly!))
Comment #4
XanoNeeds screenshot.
Comment #5
drunken monkeyNeeds screenshot, work, and removal of
debug()
calls, which I left, as always, lying around …Revised patch attached (only minus three
debug()
lines and plus oneisset()
).Comment #6
drunken monkeyComment #8
drunken monkey#5: tablesort_active-5.patch queued for re-testing.
Test works fine locally, and I couldn't tell what in my patch would influence that test.
Comment #9
drunken monkeySo, tests pass – anyone wants to set this to RTBC?
Comment #10
bleen CreditAttribution: bleen commentedI dont know if webchick/dries will be cool with removing a whole function like this after we have released beta.
On the other hand this does seem to be the correct way to fix this bug
extra space
Anyone else want to chime in?
(needs work for the white space)
Powered by Dreditor.
Comment #11
drunken monkeyYou're right, of course, this came up in another issue as well. Even if core doesn't use the function, we can't be sure what contrib modules already do. Removing this now would be a completely unnecessary API change.
So, keeping the function without using it anymore, and adding a @todo for Drupal 8.
Also removed the two superfluous lines.
Comment #12
drunken monkeyOops, seems like the
DRUPAL_ROOT
for thedrupal_add_js()
call was a stupid idea after all …Comment #13
drunken monkey#12: tablesort_active-12.patch queued for re-testing.
Still seems to work for me, nobody else here interested?
Comment #14
drunken monkey#12: tablesort_active-12.patch queued for re-testing.
Comment #16
drunken monkeyWeird, test results above show this passed … Also works for me locally.
However, needs a re-roll anyways, since -p0 is now deprecated. See attached.
Comment #17
bleen CreditAttribution: bleen commentedThis now needs to be fixed in D8 first, so maybe you want to take care of that "todo" for the D8 versin of the patch
Only then will it be backported to D7
Comment #18
drunken monkeyAh, you're right, of course.
Comment #19
bleen CreditAttribution: bleen commentedThis patch is roughly the same as the patch in #18 but it reduces the amount of code needed by checking that $cell is an array much earlier on. I'm happy with this... lets get one more review for good luck and then we can mark RTBC
Comment #21
bleen CreditAttribution: bleen commented#19: 838096-tablesort_active-D8-18.patch queued for re-testing.
Comment #23
drunken monkeyI can reproduce this locally:
fatal: corrupt patch at line 116
Please re-roll. (Couldn't tell what's wrong with the patch or that line, though.)
Comment #24
bleen CreditAttribution: bleen commentedhmmm ... try this Mr. Bot
Comment #25
drunken monkeyComments should go on a separate line and have no more than 80 characters per line.
(Yes, I know, I had that wrong, too, but that was a long time ago …)
While I personally like this style better, core policy seems to be to omit that newline between last method and end of class.
Attached: a patch that should fix this.
(By the way: The "18" (or, now, "25") at the end of the filename stands for the comment number, to easily keep track of what version of the patch that is. Meaning, you should increment that number when creating new patches.)
Powered by Dreditor.
Comment #26
fietserwinIssue #1277874: table cells incorrectly get class 'active' seems to target the same code. However, it looks like the patch for this issue may - as an unforeseen but positive side effect - solve that issue as well.
Comment #27
drunken monkeyMight it, or does it? In the latter case, we could just call the other one a duplicate and maybe make additional efforts to get this one in.
Comment #28
fietserwinI changed the patch for the move to /core and reviewed and tested it as well.
Remarks:
$this-> assertTrue (...)
assertEqual(..., 1, ...)
aspreg_match
returns an int or false,Considering that my changes have nothing to do with the "real code changes" code changes in the patch itself, I consider this one RTBC, but would like to ask bleen18 or drunken money (or anyone else) to have a last look at it and really set it to RTBC.
Comment #29
bleen CreditAttribution: bleen commentedI'm happy with the changes from #25 & #28 ...
Comment #30
fietserwinOK, than we set it to RTBC.
Comment #31
xjmThanks for your work on this! Please don't mark your own patch RTBC, though. :)
Comment #32
fietserwin@bleen18: so you will have to set it to RTBC yourself.
Comment #33
xjmMinor thing: This should be just one line, less than 80 chars.
Can we get some inline comments in this wall of assertions? Hard to scan.
Also, I don't think bleen's question from #10 has been addressed yet:
That bit is not backportable, although it is fine for D8. So it would be good to get a separate D7 patch along with the D8 that does not remove the function.
Comment #34
fietserwin- #11 addresses #10, though maybe not very explicitly. In D7 we leave that function as is, it just won't be called anymore by theme_table(). Patch for D7 is foreseen after the patch for D8 gets in.
- Comments could indeed be added. I will see what I can do.
Comment #35
fietserwinWell, that was not much I did since then :( Maybe someone else can step up? I'm quite busy with other modules and projects that feed me.
Comment #47
quietone CreditAttribution: quietone at PreviousNext commentedTriage during a BugSmash group triage meeting.
There has been no activity here for 10 years, so maybe this has been resolved?
Is this issue still a problem?
Since we need more information to move forward with this issue, I am keeping the status at Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #48
drunken monkeyWell, it’s been “fixed” in Drupal 8 insofar as that apparently doesn’t provide the
active
class on the sorted column anymore, so can’t make mistakes in that regard, either. However, the bug is still present in Drupal 7 – see screenshots. Attached is also a slightly modified re-roll of #16, the last D7 patch.