Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

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

Open
timgws opened this issue Sep 28, 2015 · 2 comments
Assignees
Labels
Milestone

Comments

@timgws
Copy link
Collaborator

timgws commented Sep 28, 2015

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 timgws added the bug label Sep 28, 2015
@timgws timgws added this to the 5.0 milestone Sep 28, 2015
@timgws timgws self-assigned this Sep 28, 2015
@timgws
Copy link
Collaborator Author

timgws commented Sep 28, 2015

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
Copy link
Collaborator Author

timgws commented Sep 28, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant