When using formatted results in the Views service, setting the 'limit' argument doesn't override the settings in the Views display.

This patch changes how the pager and limit settings are overridden:

if (empty($offset)) {
  $view->set_use_pager(TRUE);
  $view->set_items_per_page($limit);
}

has been changed to

if (empty($offset)) {
  foreach ($view->display as $display) {
    $display->display_options['items_per_page'] = $limit;
    $display->display_options['offset'] = $offset;
  }
}

Comments

karlshea’s picture

StatusFileSize
new619 bytes

Hmmm... looks like the file attachment didn't go through? Here is the patch.

karlshea’s picture

Actually, it looks like you need both? One seems to be for formatted results, and the other for unformatted.

marcingy’s picture

Status: Needs review » Needs work
voxpelli’s picture

Closed #717752: views.get ignores offset, limit if output_format set to TRUE as a duplicate of this - that issue had an alternate patch to this one - I'm unsure about both though

karlshea’s picture

Version: 6.x-2.0-beta1 » 6.x-2.0

This is still not-functional in 2.0. I've been trying to get something working at all that covers lots of the cases, because I use both formatted and unformatted results from this service on the site I'm developing.

I'll try to wade through the views documentation, but obviously (unsurprisingly) there is some confusion as to the correct way to return ranged or paged results from a view. Does anyone actually know how this is supposed to work?

karlshea’s picture

StatusFileSize
new976 bytes

This seems to fix the offset issue with formatted results

karlshea’s picture

And that patch still doesn't include the limit functionality

karlshea’s picture

StatusFileSize
new1.14 KB

Which is now included.

Views seems to ignore the items per page on the selected display, and instead uses the default display's settings. So this patch includes the above patch, plus sets items per page if $limit has a value.

kaw3939’s picture

When is this going to be added to the released version? I am having the same problem and I can't get the patch to apply correctly.

marcingy’s picture

When a working patch has been supplied and the patch has been marked as review by the community. I personally don't use the views service so I won't be working on fixing this but will happily apply a patch one it is signed off as working.

karlshea’s picture

StatusFileSize
new1.23 KB

Patch for 2.0 attached.

I really would like someone else that uses this service to take a look and make sure it's working for them. I'm using both the formatted and unformatted cases and it seems to be working, but I haven't tested all of the different limit and offset combinations. Either way, it's definitely working better than before (i.e. not at all).

karlshea’s picture

Status: Needs work » Needs review
aaronl’s picture

Hey guys, I applied this patch and it worked great.
Whereas before the "offset" filter was overriding the "limit" filter I wasn't getting anywhere near the response I needed.
Now it seems to be following the offset and limit filters, respectively
Ill chime back in if I get any errors or breaks while I keep working on this, but for now it seems to be working fine.

skyredwang’s picture

#11: views_limit_patch-2.0.patch queued for re-testing.

kylebrowning’s picture

Status: Needs review » Closed (fixed)

THis is fixed in 2.2