Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

Filtering By Date

Open clipsmm opened this issue 10 years ago • 9 comments

So i have rendered the table now i want use date range picker to filter data by sending it to a controller and then loaded back to the view

clipsmm avatar Nov 09 '14 14:11 clipsmm

what steps did you take already?

Chumper avatar Nov 25 '14 16:11 Chumper

I had to abandon the simple {{$table->render()}}, {{$scripts->render()}} and use raw jquery var table = $('#data-table').DataTable({ "processing" : true, "serverSide": true, "order" : [[0, "desc"]], "ajax" : "{{route('api.bill')}}", "columnDefs": [ { "targets": "_all", "defaultContent": "" } ]
});

and then used

table.ajax.url(link).load();

clipsmm avatar Nov 26 '14 09:11 clipsmm

But now i have a search problem...tn/7

clipsmm avatar Nov 26 '14 10:11 clipsmm

You try?

http://www.datatables.net/plug-ins/api/fnReloadAjax

$('#table').dataTable().fnReloadAjax();

And Callback

            fnServerParams: function(aoData) {
                aoData.push({name: "site_id", value: $('#site').val()});
            }

thienhung1989 avatar Dec 16 '14 03:12 thienhung1989

Hello mita / thienhung

Did you resolve these problems? I'm struggling to create a date-range filter (external) but it's just not working.... :(

ixperiencenl avatar Mar 05 '15 14:03 ixperiencenl

When filter with data-ranger, you must add param and proccess data before Call Datatable::query or collection: Example: WHen change Combox Site -> auto reload to filter Datatable.

    $(document).ready(function() {
        grid = new GridHelper('#article-list', {
            url: '{{ URL::route('articleListData') }}',
            showCheckbox: true,
            deleteUrl: '{{ URL::route('articleDeleteList') }}',
            rowClick: function(tr) {
                var id = tr.find('.action_chk').val();
                var url = '{{ route('articleShow', array('articleId' => '')) }}' + '/' + id;
                gotoUrl(url);
            },
            fnServerParams: function(aoData) {
                aoData.push({name: "site_id", value: $('#site').val()});
            }
        });
        grid.setup();
        $('#site').change(function(){
            grid.reload();
        });
    });

PHP proccess

        $siteId = Input::get('site_id');
        $articleList = DB::table('news')
            ->leftJoin('category', 'category.id', '=', 'news.category_id')
            ->leftJoin('site','site.id','=','category.site_id')
            ->select(
                'news.id',
                'site.site_name as siteName',
                "category.category_name",
                'news.title',
                'news.type',
                'news.status',
                'publish_date',
                'news.id as comment'
            );
        if (!empty($siteId) && ($siteId != 'all')) {
            $articleList->where('site_id', '=', $siteId);
        }
        return  Datatables::....

Good Luck!!

thienhung1989 avatar Mar 06 '15 17:03 thienhung1989

@Chumper, would it be possible to enable the wiki on this project so that we can save comments (such as @thienhung1989's above) for other people who might want to perform specific functionality?

Basically, providing a "Cookbook Wiki" with hints and tips for doing things like sorting columns/grouping and changing the fnServerParams function to add data on AJAX requests & changing the content of columns on the client side?

timgws avatar Mar 09 '15 01:03 timgws

just created it

Chumper avatar Mar 09 '15 01:03 Chumper

Thank you @thienhung1989 ! I'll give it a try this week and thank you @Chumper for this great package and the creation of the wiki :+1:

ixperiencenl avatar Mar 09 '15 09:03 ixperiencenl