我想在两个值之间过滤数据表,当前工作两个日期之间的范围,但我想在列数量的最小值和最大值之间进行过滤。 我想首先显示所有数据,这是现在正在工作,但我想使用ajax返回两个金额之间的过滤表
视图:
<div class="input-amountrange input-group" id="amountrange">
<input type="text" class="input-sm form-control" name="start_amount" id="start_amount" />
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" name="end_amount" id="end_amount"/>
</div>
datatable ajax:
var oTable = $('#users-table').DataTable({
dom: 'flBrtip',
buttons: [
'excelHtml5',
'csvHtml5',
'pdfHtml5'
],
stateSave: true,
paging: true,
pagingType: 'simple_numbers',
lengthMenu: [ [10,15, 30, 50, -1 ], [ 10,15, 30, 50, "All" ] ],
processing: true,
serverSide: true,
ajax: {
url: 'custom-filter-data',
data: function(d) {
d.start_date = $('input[name=start_date]').val();
d.end_date = $('input[name=end_date]').val();
d.start_amount =
$('input[name=start_amount]').val();
d.end_amount = $('input[name=end_amount]').val();
}
},
columns : [
{ data: 'details', name: 'details' },
{ data: 'postingdate', render: function (data) {
var date = new Date(data);
var month = date.getMonth() + 1;
return (month.length > 1 ? month : "0" + month) + "/" + date.getDate() + "/" + date.getFullYear();} },
{ data: 'description', name: 'description' },
{ data: 'amount', name: 'amount' },
{ data: 'type', name: 'type' },
{ data: 'vendor_name', name: 'vendors.vendor_name', mRender: function (data, type, row) {
return '<label hidden>'+data+'</label> <input type="text" id="vendor_name" class="vendor_name" data-id="'+row.id+'" onClick="this.select();" value="'+data+'">';
}
},
{ data: 'vendor_id', mRender: function (data, type, row) {
return '<label hidden>'+data+'</label> <input type="text" id="vendor_no" class="vendor_no" onClick="this.select();" value="'+data+'">';
}
},
{ data: 'category_name', name: 'excategories.category_name', mRender: function (data, type, row) {
return '<label hidden>'+data+'</label> <input type="text" id="category_name"
class="category_name" data-id="'+row.id+'" onClick="this.select();"
value="'+data+'">';
}
},
],
pageLength: 10,
});
oTable.draw();
控制器
public function getCustomFilterData()
{
$arrStart = explode("/", Input::get('start_date'));
$arrEnd = explode("/", Input::get('end_date'));
$start = Carbon::create($arrStart[2], $arrStart[0], $arrStart[1], 0, 0, 0);
$end = Carbon::create($arrEnd[2], $arrEnd[0], $arrEnd[1], 23, 59, 59);
$vendorTableName= with(new Vendors())->getTable();
$categoryTableName= with(new Excategories())->getTable();
$orders=Checks::select(["checks.*","vendors.vendor_name","excategories.category_name"])->between($start, $end)->leftJoin($vendorTableName,$vendorTableName.".vendor_id","=","checks.vendor_id")->leftJoin($categoryTableName,$categoryTableName.".category_id","=","checks.category_id");
return Datatables::of($orders)->make( TRUE );
}
答案 0 :(得分:0)
您需要创建自定义过滤器并将其应用于数据表(https://yajrabox.com/docs/laravel-datatables/master/filter-column)