看来我的选择是错误的。我在数据表中想要的是每个主管名称都可以有一个包含员工姓名的子行。但我得到的是:{ "id": "2", "name_supervisor": "Alex", "name": "testStaff4", "manager_id": "2", "role_id": "1"},{ "id": "1", "name_supervisor": "Andika", "name": "testStaff1", "manager_id": "1", "role_id": "1"}这是我的查询:$supervisors = DB::table('supervisors')->join('users','users.manager_id','=','supervisors.id') ->select(['supervisors.id','supervisors.name_supervisor','users.name','users.manager_id','users.role_id']) ->where('users.role_id',1) ->orWhere('users.role_id',null) ->groupBy('supervisors.name_supervisor'); return Datatables::of($supervisors)->make(true);这是我的带有子行的 js 数据表:function format ( d ) { // `d` is the original data object for the row return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+ '<tr>'+ '<td>Name:</td>'+ '<td>'+d.name+'</td>'+ '</tr>'+ '</table>'; } $(document).ready(function() { var table = $('#ajax_data').DataTable({ processing: true, serverSide: true, ajax: 'supervisor/json', dom: '<"top"f>rt<"bottom"lip><"clear">', columnDefs: [{"className": "text-center", "targets": "_all"}], columns: [ { "className": 'details-control', "orderable": false, "data": null, "defaultContent": '' }, { data: 'name_supervisor', name: 'supervisors.name_supervisor' } ] }); } );
添加回答
举报
0/150
提交
取消