Collection implementation of aLengthMenu with "All" option
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.
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.
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:
- Logic test to see if the value of
$this->limitis -1 and if so, set it tonullwhen passed toslice() - Logic test to see if the value of
$this->limitis "NaN" (which DataTables will pass for values it doesn't understand such as null, or 0) and if so, set it tonullwhen passed toslice().
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.