Skip to content

Commit

Permalink
Fix for issue zofe#431: Not all records are exported when calling Dat…
Browse files Browse the repository at this point in the history
…aGrid::buildCSV()
  • Loading branch information
sroutier committed May 7, 2018
1 parent ce0cbf3 commit 206d224
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,19 @@ public function build()
case "PDOStatement":
//orderby is handled by the code providing the PDOStatement

//calculate page variable.
$limit = $this->limit ? $this->limit : 100000;
$current_page = $this->url->value('page'.$this->cid, 0);
$offset = (max($current_page-1,0)) * $limit;
// Calculate page variable.
// $limit is set to only export a subset
if (isset($this->limit)) {
$limit = $this->limit;
$current_page = $this->url->value('page'.$this->cid, 0);
$offset = (max($current_page-1,0)) * $limit;
}
// $limit is null to export every records.
else {
$limit = null;
$current_page = 0;
$offset = 0;
}

$rows = array();
$skip = $cnt = 0;
Expand All @@ -195,11 +204,15 @@ public function build()
$skip++;
continue;
}
//gather the rows to render
elseif ($cnt <= $limit ) {
//gather the rows to render.
else {
$rows[$cnt] = $row;
$cnt++;
}
// If limit is set and we are passed it, break out of loop.
if (isset($limit) && ($cnt > $limit)) {
break;
}
}

$this->data = $rows;
Expand All @@ -226,9 +239,19 @@ public function build()
}
}

$limit = $this->limit ? $this->limit : 100000;
$current_page = $this->url->value('page'.$this->cid, 0);
$offset = (max($current_page-1,0)) * $limit;
// $limit is set to only export a subset
if (isset($this->limit)) {
$limit = $this->limit;
$current_page = $this->url->value('page'.$this->cid, 0);
$offset = (max($current_page-1,0)) * $limit;
}
// $limit is null to export every records.
else {
$limit = count($this->source);
$current_page = 0;
$offset = 0;
}

$this->data = array_slice($this->source, $offset, $limit);
$this->total_rows = count($this->source);
$this->paginator = new LengthAwarePaginator($this->data, $this->total_rows, $limit, $current_page,
Expand Down

0 comments on commit 206d224

Please sign in to comment.