Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] Add support for manual setting of filtered count (#1516) #1743

Merged
merged 1 commit into from
May 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 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 filtered records manually.
*
* @param int $total
* @return $this
*/
public function setFilteredRecords($total)
{
$this->filteredRecords = $total;

return $this;
}

/**
* Skip pagination as needed.
*
Expand Down Expand Up @@ -540,6 +553,16 @@ public function toJson($options = 0)
return $this->make();
}

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

/**
* Perform necessary filters.
*
Expand All @@ -556,7 +579,7 @@ protected function filterRecords()
}

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

/**
Expand Down