Skip to content

Commit

Permalink
add support for manual setting of filtered count
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickwarner committed May 16, 2018
1 parent b2d9df3 commit 73ad493
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/DataTableAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ public function setTotalRecords($total)
return $this;
}

/**
* Set total records manually.
*
* @param int $total
* @return $this
*/
public function setFilteredRecords($total)
{
$this->filteredRecords = $total;

return $this;
}

/**
* Skip pagination as needed.
*
Expand Down Expand Up @@ -556,7 +569,7 @@ protected function filterRecords()
}

$this->columnSearch();
$this->filteredRecords = $this->isFilterApplied ? $this->count() : $this->totalRecords;
$this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/QueryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public function totalCount()
return $this->totalRecords ? $this->totalRecords : $this->count();
}

/**
* Count total items.
*
* @return int
*/
public function filteredCount()
{
return $this->filteredRecords ? $this->filteredRecords : $this->count();
}

/**
* Counts current query.
*
Expand Down Expand Up @@ -148,7 +158,6 @@ protected function prepareCountQuery()
if (! $this->isComplexQuery($builder)) {
$row_count = $this->wrap('row_count');
$builder->select($this->connection->raw("'1' as {$row_count}"));
$builder->setBindings([], 'select');
}

return $builder;
Expand Down

0 comments on commit 73ad493

Please sign in to comment.