我有以下这种格式的收藏
fee
这是我的控制器和数据表的代码
[
{
activitydate: "2019-07-08",
producidos: 1693,
muertos: 0,
propagados: 2,
stock: 1691
},
{
activitydate: "2019-07-05",
producidos: 18,
muertos: 0,
propagados: 0,
stock: 18
},
{
activitydate: "2019-07-04",
producidos: 14,
muertos: 0,
propagados: 0,
stock: 14
}
]
javascript代码
$final_c=collect();
....
.....
...
$final_c->push([
"activitydate"=>$key,
"producidos"=>$producidos,
"muertos"=>$muertos,
"propagados"=>$propagados,
"stock"=>$stock
]);
}
return $this->ajax($final_c);
public function ajax($activity)
{
return Datatables::of($activity)
->addColumn('activitydate',function($activity)
{
return $activity->activitydate;
})
->addColumn('producidos',function($activity)
{
return $activity->producidos;
})
->addColumn('muertos',function($activity)
{
return $activity->muertos;
})
->addColumn('propagados',function($activity)
{
return $activity->propagados;
})
->addColumn('stock',function($activity)
{
return $activity->stock;
})->rawColumns(['activitydate','producidos','muertos','propagados','stock'])->make(true);
}
当我尝试通过它时,我会得到
异常消息:↵↵试图获取非对象的属性
但是,如果我更改数据表中的值的方式,则会得到以下信息
代码已更改
function makeColumns()
{
return [
{ data: 'activitydate', className: "text-center" , orderable: false, searchable: false},
{ data: 'producidos', className: "text-center" },
{ data: 'muertos', className: "text-center" },
{ data: 'propagados', className: "text-center" },
{ data: 'stock', className: "text-center" },
];
}
$('#up_table').DataTable({
processing: true,
serverSide: true,
ajax:{
url:"/api/up-table/dt",
},
columns: makeColumns(),
language: {
search: "_INPUT_",
searchPlaceholder: "BUSCAR..."
},
"lengthMenu": [[ 50,10, 20, 40, 80, 160,-1 ],[ 'Elegir','10', '20', '40', '80', '160','Todo']],
/*initComplete: function()
{
this.api().columns().every(
function()
{
var column = this;
//added class "select"
var select = $('<select class="select" multiple="multiple" PlaceHolder="SELECCIONAR"><option value=""></option></select>')
.appendTo($(column.footer())
.empty())
.on('change', function()
{
var vals = $('option:selected', this).map(function(index, element) {
return $.fn.dataTable.util.escapeRegex($(element).val());
}).toArray().join('|');
column .search(vals.length > 0 ? '' + vals + '' : '', true, false)
.draw();
});
column .data()
.unique()
.sort()
.each(function(d, j)
{
select.append('<option value="' + d + '">' + d + '</option>')
});
});
//select2 init for .select class
$(".select").select2();
}*/
});
DataTables警告:表id = up_table-请求第0行第0列的未知参数'id'。有关此错误的更多信息,请
在“网络”标签中,我可以看到获得的数据,如下所示:
public function ajax($activity)
{
return Datatables::of($activity)
->addColumn('activitydate',function($activity)
{
return $activity["activitydate"];
})
->addColumn('producidos',function($activity)
{
return $activity["producidos"];
})
->addColumn('muertos',function($activity)
{
return $activity["muertos"];
})
->addColumn('propagados',function($activity)
{
return $activity["propagados"];
})
->addColumn('stock',function($activity)
{
return $activity["stock"];
})->rawColumns(['activitydate','producidos','muertos','propagados','stock'])->make(true);
}
数据表需要什么样的格式?