[英]How to access json object/data in datatable server side processing in Laravel 5.2?
We're using with datatables on a new project and due to the large amount of data we are working with, we are using the server side processing of datatables.But right now we're trying to figure out how to get all the data from the server through datatables.As I use the Custom HTTP variables server side processing and as I take a look with the data returned, there are no values coming from the database. 我们正在新项目上使用数据表,由于正在处理大量数据,因此我们正在使用服务器端对数据表的处理。但是现在,我们正在尝试弄清楚如何从中获取所有数据当我使用自定义HTTP变量在服务器端进行处理时,当我查看返回的数据时,数据库中没有任何值。 How could I access the data?
如何访问数据? Please help.
请帮忙。 Thanks a lot.
非常感谢。 Here are my code
这是我的代码
javascript: javascript:
$('#table-prod-contents').DataTable({
processing: true,
serverSide: true,
ajax: $.fn.dataTable.pipeline( {
url: '{{ url("postproductsdata") }}',
pages: 6000, // number of pages to cache
"data": function ( d ) {
console.log(d);
}
} ),
columns: [
{data: 'id', name: 'id'},
{data: 'category', name: 'category'},
{data: 'pharmaceutical', name: 'pharmaceutical'},
{data: 'description', name: 'description'},
{data: 'type', name: 'type'},
{data: 'unit', name: 'unit'},
{data: 'price', name: 'price'},
{data: 'created_at', name: 'created_at'},
],
});
The console,log only shows the data shown in the image below: 控制台日志仅显示下图中显示的数据:
As I look inside the Object, there is no value of an id. 当我查看对象内部时,没有id的值。 Something like id: 31
编号:31
Controller.php Controller.php
public function anyData()
{
$conditionTxt = "Medical and Lab Supplies";
$products = Product::where('category', 'ILIKE', '%'.$conditionTxt.'%')
->orderBy('created_at', 'desc')
->get();
return Datatables::of($products)->make(true);
}
Option ajax.data
allows to define function to manipulate the data before it's sent to the server. 选项
ajax.data
允许定义函数以在将数据发送到服务器之前对其进行操作。
You could use ajax.dataSrc
to get access to data received from the server, however you're also using pipelining which doesn't allow that. 您可以使用
ajax.dataSrc
来访问从服务器接收的数据,但是您还使用了不允许的流水线 。
Use either drawCallback
option along with ajax.json()
API method to get access to retrieved data or createdRow
option or xhr.dt
event. 使用
drawCallback
选项和ajax.json()
API方法可以访问检索到的数据,或者可以使用createdRow
选项或xhr.dt
事件。
For example: 例如:
$('#table-prod-contents').DataTable({
processing: true,
serverSide: true,
ajax: $.fn.dataTable.pipeline( {
url: '{{ url("postproductsdata") }}',
pages: 6000, // number of pages to cache
"data": function ( d ) {
console.log(d);
}
} ),
drawCallback: function(settings){
var api = this.api();
console.log(api.ajax.json());
},
columns: [
{data: 'id', name: 'id'},
{data: 'category', name: 'category'},
{data: 'pharmaceutical', name: 'pharmaceutical'},
{data: 'description', name: 'description'},
{data: 'type', name: 'type'},
{data: 'unit', name: 'unit'},
{data: 'price', name: 'price'},
{data: 'created_at', name: 'created_at'},
],
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.