Chumper / Datatable

This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
https://github.com/Chumper/Datatable
388 stars 154 forks source link

setNoGroupByOnCount() does not correctly show counts when there is a group by clause. #336

Open timgws opened 9 years ago

timgws commented 9 years ago

screen shot 2015-09-28 at 4 10 31 pm

There are three things wrong with this image after ->setNoGroupByOnCount() was set on the Datatable::query:

  1. The amount of entries (60) is when the group by is not run.
  2. The amount filtered by should be the amount of entries (see # 1)
  3. When the Group By is 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.

timgws commented 9 years ago

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.

timgws commented 9 years ago

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();
    }
}