Yajra数据表搜索栏在两个文本类型数据表显示空x1c 0d1x后不工作
搜索后
Jquery ->
$(function () {
var table = $('#projectcashflow_data').DataTable({
processing: true,
serverSide: true,
lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
dom: 'Blfrtip',
"buttons": [
{
"extend": 'excelHtml5',
"title": 'Expense_Manage',
"text": '<button class="btn"><i class="fa fa-file-excel-o" style="color: green;"></i> Excel</button>',
"titleAttr": 'Excel',
exportOptions: {
modifier : {
page : 'all',
},
rows: { order:'current', search: 'none' },
columns: [1, 2, 3, 4, 5],
}
},
],
ajax: "{{ route('projectcashflow.load-projects-cashflow') }}",
columns: [
{data: 'DT_RowIndex', name: 'DT_RowIndex'},
{data: 'edit.projects_name', name: 'projects_name'},
{
data: 'action', name: 'action',
orderable: true,
searchable: true
},
],
});
});
服务器端代码(Laravel)My DataTable查询函数如下。->
public function load_projects_cashflow(Request $request){
if($request->ajax()){
$data = ProjectCashflow::select('project_cashflows.*','projects.project_name')
->leftjoin('projects', 'projects.id', 'project_cashflows.project_id')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$dataedit = route('projectcashflow.edit-projectscashflow',$row->id);
$actionBtn = "<a class='' style='margin-right:15px' href='{$dataedit}'
><i class='bx bx-edit-alt me-1'></i></a>";
$viewButton = "<a style='margin-right:15px' class='projectcashflowdetails' data-id='{$row->id}' data-toggle='modal' data-target='#projectcashflowdetails' style='cursor: pointer;' ><i class='fa-solid fa-eye me-1'></i></a>";
$deletebutton = "<a class='projectcashflow_delete' id='projectcashflow_delete' style='cursor: pointer;' data-id='$row->id'><i class='bx bx-trash-alt me-1'></i></a>";
return $actionBtn.' '.$viewButton.' '.$deletebutton;
})
->editColumn('edit', function($row){
$projectname = "<a class='projectcashflowdetails' data-id='{$row->id}' data-toggle='modal' data-target='#projectcashflowdetails' style='cursor: pointer;' >$row->project_name</a>";
return [
'projects_name' => $projectname,
];
})
->escapeColumns('edit')
->rawColumns(['action','edit'])
->make();
}
}
我使用了左连接查询。现在的问题是Yajra DataTable搜索栏不工作。它既没有给出任何错误,也没有搜索结果。
需要一个解决方案,每件事都在代码中很好,但我不知道为什么不工作,
1条答案
按热度按时间tjvv9vkg1#
您可以使用
filter()
方法进行搜索。例如:自定义过滤。参见:https://yajrabox.com/docs/laravel-datatables/master/filter-column
下面是我自己的项目的一个例子: