Datatable
Datatable copied to clipboard
Filtering By Date
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
what steps did you take already?
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();
But now i have a search problem...tn/7
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()});
}
Hello mita / thienhung
Did you resolve these problems? I'm struggling to create a date-range filter (external) but it's just not working.... :(
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!!
@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?
just created it
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: