我使用的是简单的数据表,但只要我使用get和laravel请求获取获取信息,Datatable就不能再在serverside上工作了:true。
JS
serverSide: true,
processing: true,
ajax: {
url: "{!! route('listOfProjectsAjax') !!}",
type: "GET",
data: ajaxData,
dataType: "JSON"
},
columns: [...
控制器
public function ListOfprojects(Request $request)
{
$inputs = $request->all();
return $this->projectRepository->getListOfProjects($inputs);
}
存储库
public function getListOfProjects($where = null)
{
$projectList = $this->project
->select( 'id','customer_name','project_name','otl_project_code','project_type','activity_type','project_status','meta_activity','region',
'country','domain','description','estimated_start_date','estimated_end_date','comments','LoE_onshore','LoE_nearshore',
'LoE_offshore','LoE_contractor','gold_order_number','product_code','revenue','win_ratio');
$data = Datatables::of($projectList)->make(true);
return $data;
}
我不明白为什么。
我再次做了一些测试,并且当我有命令时,服务器端进行排序,搜索无效:
data: ajaxData,
来自我的ajax请求。
如果我删除它,那么一切正常,我可以进行服务器端搜索,排序,......
以下是来自服务器的2条回复: 没有数据:ajaxData,:
{"draw":3,"recordsTotal":7,"recordsFiltered":7,"data":[{"id":66,"customer_name":"Cisco","project_name":"LAN2","project_type":"","activity_type":"","meta_activity":"","region":"","country":"","customer_location":"","domain":"","description":null,"estimated_start_date":"0000-00-00","estimated_end_date":"0000-00-00","comments":null,"LoE_onshore":0,"LoE_nearshore":0,"LoE_offshore":0,"LoE_contractor":0,"gold_order_number":"","product_code":"","revenue":10,"project_status":"","otl_project_code":"","win_ratio":0,"created_by_user_id":1,"otl_validated":0,"created_at":"2017-06-16 18:14:53","updated_at":"2017-06-16 20:23:26"}, ...],"queries":[{"query":"select count(*) as aggregate from (select '1' as `row_count` from `projects`) count_row_table","bindings":[],"time":0.18},{"query":"select * from `projects` order by `customer_name` asc limit 10 offset 0","bindings":[],"time":0.27}],"input":{"draw":"3","columns":[{"data":"id","name":"id","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"project_name","name":"project_name","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"customer_name","name":"customer_name","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"otl_project_code","name":"otl_project_code","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"project_type","name":"project_type","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"meta_activity","name":"meta_activity","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"region","name":"region","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"country","name":"country","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"domain","name":"domain","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"description","name":"description","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"estimated_start_date","name":"estimated_start_date","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"estimated_end_date","name":"estimated_end_date","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"comments","name":"comments","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"LoE_onshore","name":"LoE_onshore","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"LoE_nearshore","name":"LoE_nearshore","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"LoE_offshore","name":"LoE_offshore","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"LoE_contractor","name":"LoE_contractor","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"gold_order_number","name":"gold_order_number","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"product_code","name":"product_code","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"revenue","name":"revenue","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"project_status","name":"project_status","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"win_ratio","name":"win_ratio","searchable":"false","orderable":"true","search":{"value":"","regex":"false"}},{"data":"","name":"actions","searchable":"false","orderable":"false","search":{"value":"","regex":"false"}}],"order":[{"column":"2","dir":"asc"}],"start":"0","length":"10","search":{"value":"","regex":"false"}}}
使用数据:ajaxData,:
{"draw":0,"recordsTotal":6,"recordsFiltered":6,"data":[{"id":65,"customer_name":"cxc","project_name":"LAN1","project_type":"","activity_type":"","meta_activity":"","region":"","country":"","customer_location":"","domain":"","description":null,"estimated_start_date":"0000-00-00","estimated_end_date":"0000-00-00","comments":null,"LoE_onshore":0,"LoE_nearshore":0,"LoE_offshore":0,"LoE_contractor":0,"gold_order_number":"","product_code":"","revenue":0,"project_status":"","otl_project_code":"","win_ratio":0,"created_by_user_id":1,"otl_validated":0,"created_at":"2017-06-16 18:14:37","updated_at":"2017-06-16 18:14:37"},...}],"queries":[{"query":"select count(*) as aggregate from (select '1' as `row_count` from `projects` where not exists (select * from `activities` where `activities`.`project_id` = `projects`.`id`)) count_row_table","bindings":[],"time":0.83},{"query":"select * from `projects` where not exists (select * from `activities` where `activities`.`project_id` = `projects`.`id`)","bindings":[],"time":0.76}],"input":{"unassigned":"true"}}
这是我的ajaxData:
function ajaxData(){
var obj = {
'unassigned': 'true'
};
return obj;
}
答案 0 :(得分:0)
您的问题很可能与select('*')
结合使用->make()
有关。软件包维护者声明永远不要使用它,因为它可能导致意外行为。请阅读此示例顶部的警告:
https://datatables.yajrabox.com/fluent/basic
尝试将控制器更改为:
$projects = DB::table('projects')
->select(['id', 'field1', 'field2', 'created_at', 'updated_at']);
return Datatables::of($projects)->make();
示例还显示了使用'GET'请求而不是'POST'。你出于某种原因需要使用“POST”吗?您还可以使用请求输入优化任务服务器端,如下所示:
$projects = DB::table('projects')
->select(['id', 'field1', 'field2', 'created_at', 'updated_at'])
->where('unassigned', $request->input('unassigned'));
答案 1 :(得分:0)
好吧,似乎发布数据的唯一方法就是这样做:
而不是使用:
data: ajaxData,
要使Laravel数据表正常工作,您需要使用:
data: function ( d ) {
d.unassigned = "true";
},