Skip to content

Commit 7c699d1

Browse files
authored
Merge pull request #2083 from consilience/9.0
[9.0] Using predefined offsets for API-driven server-side(ish) DataTables.
2 parents 4e5618f + 59742e3 commit 7c699d1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/CollectionDataTable.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class CollectionDataTable extends DataTableAbstract
2323
*/
2424
public $original;
2525

26+
/**
27+
* The offset of the first record in the full dataset.
28+
*
29+
* @var int
30+
*/
31+
private $offset = 0;
32+
2633
/**
2734
* Can the DataTable engine be created with these parameters.
2835
*
@@ -136,7 +143,7 @@ function ($row) use ($column, $keyword, $regex) {
136143
public function paging()
137144
{
138145
$this->collection = $this->collection->slice(
139-
$this->request->input('start'),
146+
$this->request->input('start') - $this->offset,
140147
(int) $this->request->input('length') > 0 ? $this->request->input('length') : 10
141148
);
142149
}
@@ -313,4 +320,19 @@ protected function resolveCallbackParameter()
313320
{
314321
return $this;
315322
}
323+
324+
/**
325+
* Define the offset of the first item of the collection with respect to
326+
* the FULL dataset the collection was sliced from. It effectively allows the
327+
* collection to be "pre-sliced".
328+
*
329+
* @param int $offset
330+
* @return $this
331+
*/
332+
public function setOffset(int $offset)
333+
{
334+
$this->offset = $offset;
335+
336+
return $this;
337+
}
316338
}

0 commit comments

Comments
 (0)