This patch provides another method for specifying the number of columns displayed in a grid view.
Starting with Views Bonus Pack v1.1, one can specify the number of columns by adding PHP code to the attributes for a grid view definition. With this patch, the number of columns for a view can be specified indirectly through the number of nodes per page or block setting on the edit view page.
This patch adds the following process for setting the number of columns in a grid view:
1. If $view->gridcount is set, then it determines the number of columns.
2. Otherwise, if the number of nodes per page or block is set (depending on if the grid is in a page or block), then the number of columns will be the greatest integer less than the square root of this value.
3. In all other cases, the number of columns defaults to 4.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views_bonus_1.patch | 1.54 KB | arithmetric |
| views_bonus_0.patch | 1.49 KB | arithmetric |
Comments
Comment #1
robloachHow do you specify the number of rows? If you have 16 nodes per page, with a $view->gridcount of 4, you know you'll only have 4 rows. With your solution, how do you control the number of rows?
Comment #2
moshe weitzman@drupal.org commentedi get that the number of rows is calculated so as to produce a square. so if you have 22 then best square is 4x4. then you have 6 pictures left over. presumably the next page is a 2x2 grid? and then a 2x1 grid. or 1x2? i don't think this will work well with the pager. you need to make the square bigger than the nu,be rof items on the page. there will often be holes at the botom, but thats needed so pager makes sense.
or i am missing something.
Comment #3
arithmetric commentedRob:
My solution does not allow the user to directly specify the number of rows. Moshe said it right, my code produces a square grid of a user-defined size. So if you want 3 rows, and you're alright with having 3 columns, then you can get that with my patch by setting the nodes per block/page in the grid view settings to 9.
Moshe:
The number of columns and rows of the grid produced by my code does not vary according to the actual number of nodes on a given page, but to the value set in the page or block settings for a grid view as 'number of nodes per page/block'. If this value is set to 9, then the grid in each page or block will be 3x3. (If there are less than 9 nodes on a given page, the grid is still filled three across the first row, then the second, and so on.)
Really this patch may not be for everyone. I wanted to be able to control the number of columns within the view settings. It would be nice if each grid view could have a user-specified number of columns and rows. That seemed like a big project. For now, this is a way to use the value that can be set for each grid view, the number of nodes per block/page, for customizing the layout.
Comment #4
robloachI think we have to somehow get a solution where you specify both number of columns and rows. Because what if you want 3 columns, and 10 rows? Or maybe even 4 columns, with 1 row (like YouTube's "Promoted Videos").
Comment #5
arithmetric commentedI'm posting an update of the original patch to correct a typo.
Rob:
What do you think about extending the grid module to alter the page/block form and allow the user to specify the number of columns and rows?
Comment #6
robloachI think using the $view->gridcount is the easiest way. I had a look at your patch, and it can get confusing when you use that solution.
If you have a view and you want 3 columns and 5 rows for the page, and 2 columns and 4 rows for the block, you'd do that following: For the page, in the PHP argument handling code, you'd put
$view->gridcount = 3;and 15 for the nodes per page (3 * 5). For the block, in the PHP argument handling code, you'd put$view->gridcount = 2;and 8 for the nodes per block (2 * 4).Yes, even that is confusing, but it's the simplest solution we can come to. To my knowledge, Views in Drupal 6 will allow the capabilities of allowing View Type arguments to be set within the form itself, so this is something that might be better to be waited on.
Comment #7
pomliane commentedThis version of Views Bonus Pack is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.
This issue has been automagically closed by a script.