Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

Collection implementation of aLengthMenu with "All" option

Open lachyn opened this issue 11 years ago • 2 comments

Hello, I am using collection engine. When I want to create custom length menu with "All" option this way:

"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],

works fine but "All" option never shows the last result and counter displays:

Showing 1 to 493 from total 494 records

It has probably something to do with "-1" in the lenght menu option, but this is according Datatables docs option fol "All"...

Did I missed something or somebody already foud a workaround for this? Thanks.

lachyn avatar Nov 06 '14 17:11 lachyn

Probably not, i know there are some errors with pagination, but i havent had the time to take a look at it. I would try to do a better job with version 3.x but atm i am short on time to work on this on my own.

Chumper avatar Nov 25 '14 16:11 Chumper

A little follow-up. This happens because line 126 of CollectionEngine.php has this:

return $this->workingCollection->slice($this->skip,$this->limit);

Here's the signature for Collection->slice():

slice(int $offset, int $length = null, bool $preserveKeys = false)

As you'll notice, when $this->limit is -1, the collection gets one record sliced off the end.

A few quick fixes are:

  1. Logic test to see if the value of $this->limit is -1 and if so, set it to null when passed to slice()
  2. Logic test to see if the value of $this->limit is "NaN" (which DataTables will pass for values it doesn't understand such as null, or 0) and if so, set it to null when passed to slice().

I'm inclined to go the second route simply because -1 might be expected behavior in some cases. Saving "NaN" cases sounds like good practice to me.

davepgreene avatar Aug 28 '15 20:08 davepgreene