Is Letting your user change number of rows returned $limit possible for views 6.x-2.11?
I am able to complete the first five (5) steps and have the exposed filter with the choices available at the top of the view. I am using the following argument code:
if( !$_GET['filter0'] ) {
$_GET['filter0'] = $limit;
}
else if (is_numeric($_GET['filter0'])) {
$limit = $_GET['filter0'];
}
else {
$limit = 100;
}
unset($filters[0]);
I am also using the Basic Validator to display all values if the argument does not validate.
If I make any selection, the view returns empty text. If I select -Any-, the view returns all values.
I am not sure where to start troubleshooting this or if there is a better approach.
Comments
Comment #1
merlinofchaos commentedI think in your argument code you can use $view->set_items_per_page($limit); In Views 3 you can do this from the UI.
Comment #2
waverate commentedI just did a quick non-production install of Views3 and it looks like this feature is nicely implemented.
However, I don't know if all my modules are ready to work with Views3, so I think I need to hold off on that.
That being said, I think my problem lies in the argument code itself in addition to adding $view->set_items_per_page($limit);
Is unset($filters[0]); still valid in Views2?
Comment #4
dawehnerunset($filters[0][); is could for views 1.x, so it will not work at all.
Comment #5
waverate commentedThank you. I was beginning to suspect that. Is there an easier way to change the $limit for views2.x than the original argument code?
Comment #6
dawehnerWell you have to write the code.
Earl already described a single function which has to be coded somewhere, in the argument validator/in a hook.
Comment #7
dawehnerThis view shows an example how to set the items per page based on random.
You should be able to do the rest.
Comment #8
waverate commentedGreat help. Now I understand what how to write argument code. The only subtlety is that the export in #7 is for views3.x. I have attached an export of the above example for views 2.x.
In the end I dropped the Exposed Filter from the original post in favour of this header:
From #7, I added a Global: Null argument with the following:
- display all values if arguement is not present
- validator: PHP code
- display all values if the argument does not validate
- PHP validate code:
I did notice that in order to get the pager working correctly, the items per page had to be greater than the highest argument that you intend to pass.
Where I am running into problems now is with the links in the header and the links generated by my sortable table. For example, if I sort my table in like:
http://example.com/test?order=nid&sort=desc
and I want to display 10 results per page, I cannot use the link in my header (http://example.com/test/10). I need to somehow generate http://example.com/test/10?order=nid&sort=desc.
Any ideas?
Comment #9
waverate commentedAttachment for #7
Comment #10
meishme commentedPerfect timing. This solution is perfect for what I need.
Comment #11
waverate commentedIt is a good solution if you don't have sortable columns or exposed filters. If that is the case, I would change the header to PHP and try and make it work with the other URL arguments.