bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

How to multiple filter_column and multiples params from column filtering ? #136

Closed prigal closed 10 years ago

prigal commented 10 years ago

Hi I have a problem with multiple filter_column.

Eg datatable :

Id | category_name | products_count | comments_count | published 1 | home | 45 | 3 | Yes 2 | garden | 23 | 12 | Yes 3 | kitchen | 23 | 4 | No 4 | saloon | 12 | 3 | Yes

I enable column filtering so I can filters on multiple columns in the same time. Eg : I want to select all categories with 23 products and that are not published, I type 23 in column products_count and No in column published.

Problem : Datatables is messing up with params and try to find published=23 and products_count=No.

Edit : If I only select all categories with 23 products, everything is ok and filters returns ids 2 and 3.

This is my code :

public function data() {
$categories = Category::leftJoin('category_product', '.category_product.category_id', '=', 'categories.id')
            ->leftJoin('products', 'category_product.product_id', '=', 'products.id')          
            ->leftJoin('category_comment', 'category_comment.category_id', '=', 'categories.id')
            ->leftJoin('comments', 'category_comment.comment_id', '=', 'comments.id')
            ->groupBy('categorie.id')
            ->select(array('categories.id', 'categories.name as category_name', DB::raw('count(distinct products.id) as products_count'), DB::raw('count(distinct comments.id) as comments_count'), DB::raw('IF(categories.published=1,\'Yes\',\'No\') as published')));

return Datatables::of($brands)
->edit_column('published', '<span class="{{$published==\'Yes\'?\'text-success\':\'text-danger\'}}">{{$published}}</span>')
 ->filter_column('products_count', 'having', DB::raw('count(distinct products.id)'), '=', '$1')
 ->filter_column('comments_count', 'having', DB::raw('count(distinct comments.id)'), '=', '$1')
->make();
}

How can I solve it ?

ktunkiewicz commented 10 years ago

That is weird... I read this few times and still cannot figure out what can be a reason here... Are you still working on this? Or maybe you found some reason of this behaviour?

prigal commented 10 years ago

I'm not working on it anymore and I did not found any reason. The bug is still in my todo list ^^

ktunkiewicz commented 10 years ago

I can help you with that if you post the requests that are made from browser and the reply from server.