我想点击yajra datatable上的复选框如果点击可用我想根据控制器条件获取数据问题是表格不刷新...这里是视图
<div class="col-sm-12">
<div class="col-sm-3"><input type="checkbox" name="available" id=available" >Available</div>
<div class="col-sm-3"> <input type="checkbox" name="unavailable" id="unavailable" >Unavailable</div>
<div class="card-title">
<a href="{{url('/admin/promocode/add')}}" class="btn btn-primary btn-sm" id="reloadTableButton"> Add New Code </a>
</div>
</div>
<div class="card-text">
<table id="items_datatable" class="table table-striped table-bordered" cellspacing="0"
width="100%">
<thead>
<tr>
<th>Code</th>
<th>Count</th>
<th>Status</th>
<th>From</th>
<th>To</th>
<th>Created At</th>
<th>Updated At</th>
<th>Actions</th>
</tr>
</thead>
</table>
<!-- Table End-->
</div>
</div>
</div>
</div> <!-- container -->
</div> <!-- content -->
</div>
这里是控制器中的功能,我希望如果我选择可用复选框,它会获取状态或活动= 1的记录,如果我点击不可用,则获取状态为0的记录,如果我检查了它们两个获取所有
public function Promocodeslist()
{
$available=Input::get('available');
$unavailable=Input::get('unavailable');
if($available ==1 && $unavailable == 0 ){
$promocodes = DB::table('promocodes')->select('id','code','userscount','active','sfrom','sto','created_at','updated_at')->where('active',1)->get();
}elseif($unavailable == 1 && $available == 0){
$promocodes = DB::table('promocodes')->select('id','code','userscount','active','sfrom','sto','created_at','updated_at')->where('active',0)->get();
}else{
$promocodes = DB::table('promocodes')->select('id','code','userscount','active','sfrom','sto','created_at','updated_at')->get();
} return Datatables::of($promocodes)->make(true);
}
这里是ajax调用
<script>
<?php $editurl = url('/admin/promocode/');?>
var available = 0;
var unavailable=0;
var ckbox = $('#available');
var ckbox1=$('#unavailable');
var table = $('#items_datatable').DataTable({
processing: true,
serverSide: true,
destroy:true,
ajax: '{!! route("promocodes_list",["available"=> 'available',"unavailable" => 'unavailable']) !!}',
columns: [
{data: 'code', name: 'code'},
{data: 'userscount', name: 'userscount'},
{data: 'active', name: 'active'},
{data: 'sfrom', name: 'sfrom'},
{data: 'sto', name: 'sto'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'},
{
data: 'id', render: function (data)
{
return "<a href='{{$editurl}}" + '/' + data + '/edit' + "' class='btn btn-w" + "arning'><i class='fa fa-pencil' data-toggle='tooltip' data-placement='top' title='Edit Deliver-Order' ></i></a> ";
}
}]
});
$('input').on('click',function () {
if (ckbox.is(':checked')) {
available = 1;
} else {
available=0;
}
table.ajax.reload();
});
$('input').on('click',function () {
if (ckbox1.is(':checked')) {
unavailable = 1;
} else {
unavailable=0;
}
table.ajax.reload();
});