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.
Basically, the odd and even css tags are not being applied to the grid.
Had to edit theme/theme.inc be adding the following:
$row_classes[] = 'row-' . (($row_number + 1) % 2 ? 'odd' : 'even');
Please see the following code snippet:
if ($row_class_special) {
$row_classes[] = 'row-' . (($row_number + 1) % 2 ? 'odd' : 'even');
if ($row_number == 0) {
$row_classes[] = 'row-first';
}
if (count($rows) == ($row_number + 1)) {
$row_classes[] = 'row-last';
}
}
Testing working. Added some CSS to my custom theme CSS and good to go. Not sure why the row-first and row-last were included but the striping code was omitted.
Comment | File | Size | Author |
---|---|---|---|
#20 | interdiff_18_20.txt | 319 bytes | tibezh |
#20 | views-grid_odd_even_row_class-TESTS_ONLY-1863358-20.patch | 2.94 KB | tibezh |
#18 | views-grid_odd_even_row_class-1863358-18.patch | 3.38 KB | tibezh |
Comments
Comment #1
dawehnerPlease always provide a patch because everything else is simply horrible to review.
Comment #2
polskikrol CreditAttribution: polskikrol commentedPlease advise on the proper process for submitting patches? Anyway I can easly obtain the original file (as I did not save it before modifying)?
Comment #3
dawehnerSee http://drupal.org/node/707484
Comment #4
crutch CreditAttribution: crutch commentedWhen using grid, and I have striping unchecked, striping remains. This is a theme issue and not views.
Comment #5
polskikrol CreditAttribution: polskikrol commentedDont think so, if you look at the code I had to add to theme/theme.inc (which is base drupal 7 file AFAIK), striping information was missing.
Just to clarify, this is when using Views, Format 'Grid', Show 'Fields'.
Comment #6
crutch CreditAttribution: crutch commentedah, I see what you saying.
---
my grid stack is looking like this with those settings
in my case the grid striping setting has no effect because the table is using my custom theme css.
Comment #7
jberg1 CreditAttribution: jberg1 commentedThank you. That helped me.
Please add to the next version.
Comment #8
haydeniv CreditAttribution: haydeniv commentedThis is still a problem in the latest version. This patch addresses it.
Comment #9
haydeniv CreditAttribution: haydeniv commentedHelps to attach patch.
Comment #10
sterndata CreditAttribution: sterndata commentedThanks for the patch. It worked for me.
Comment #11
haydeniv CreditAttribution: haydeniv commentedLooks like this is ready to go unless we need a test for this tiny change.
Comment #12
silurius CreditAttribution: silurius commentedI think the issue applies to both grids and tables. My table formats are not respecting the striping checkbox (first, even/odd and last classes only).
Lines 632-635 from the tables section of theme.inc:
Comment #12.0
silurius CreditAttribution: silurius commentedYeah, added some text highlighting within code tags, didnt work well.... correcting.
Comment #13
Jim Bacon CreditAttribution: Jim Bacon commentedThe patch in #9 applies striping classes of "row-odd" and "row-even" in the function template_preprocess_views_view_grid().
Meanwhile, it looks to me as if template_preprocess_views_view_table() applies striping classes of "odd" and "even" while template_preprocess_views_view_unformatted() applies striping classes of "views-row-odd" and "views-row-even".
Would it not be better to use the same class names for striping for Grid, Table and Unformatted outputs?
Comment #14
dawehnerChanging the current classes in existing sites will cause avoidable damage. Can't we manually opt in for those classes?
I haven't seen stripes on grids often.
Comment #15
nerdoc CreditAttribution: nerdoc commentedIt's not about stripes. It's about odd/even.
I e.g. need these for adding float: left/right to images within these rows.
Comment #16
patrick.norris CreditAttribution: patrick.norris commentedRerolling against latest (7.x-3.29).
Comment #17
DamienMcKennaComment #18
tibezh CreditAttribution: tibezh at Drupal Ukraine Community, jobiqo - job board technology commentedI've checked a patch from the #16 comment, looks good, but it will be better to have a little test.
A patch is attached.
Comment #19
joseph.olstadlooks great, has tests, the 100% for sure RTBC would be to have a tests only run which fails.
Comment #20
tibezh CreditAttribution: tibezh at Drupal Ukraine Community, jobiqo - job board technology commentedSure, you are right. Added a patch with tests only and an interdiff to check difference quickly.
Comment #22
joseph.olstadGreat work!