Datatable
Datatable copied to clipboard
setNoGroupByOnCount() does not correctly show counts when there is a group by clause.

There are three things wrong with this image after ->setNoGroupByOnCount() was set on the Datatable::query:
- The amount of entries (60) is when the
group byis not run. - The amount
filtered byshould be the amount of entries (see # 1) - When the
Group Byis run, only 20 items are returned by the query, which means there are a handful of data-table pages that have empty rows.
This is on the master branch on a Laravel 4.0 codebase.
Actually, never mind, it's because I should have used setDistinctCountGroup...
I will leave this open, because I think we should clarify the usage for 5.0.
For future reference, this is how I was using the datatable, along with QueryBuilderParser.
<?php
class ItemController extends Controller
{
public function get_Datatable(Request $userRequest, ItemQueryRespository $iqr, $batch_id = 1)
{
if (!Datatable::shouldHandle()) {
return View::make('datatable');
}
$userRequest->canAccessBatch($batch_id);
//get filters
$post = Input::All();
if (isset($post['rules'])) {
$query = $iqr->build($post['rules']);
} else {
/**
* Default rules when nothing was posted from the QueryBuilderParser
*/
$query = $iqr->build()
->where('active', 1)
->where('visible', 1);
}
$query = $query->where('batch_id', '=', 1);
if (isset($post['groupByVendor']) && $post['groupByVendor'] == 'true') {
$query->groupBy('item_vendor');
}
//return the datatable result
$columns = array(
'item_name', 'item_description', 'item_vendor'
);
return Datatable::query($query)
->showColumns(array_merge(array('id'), $columns))
->searchColumns($columns)
->orderColumns($columns)
->setDistinctCountGroup()
->make();
}
}