简体   繁体   English

如何在Laravel 5.2中的数据表服务器端处理中访问json对象/数据?

[英]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.

相关问题 如何在不进行服务器端处理的情况下以数据表的形式加载数据 - How to load data in chunks in a datatable without server side processing 服务器端数据表处理但数据不显示 - Server-side datatable processing but data not showing 如何访问 ajax.data object 进行服务器端处理(jquery DataTables)? - How to access the ajax.data object for server-side processing (jquery DataTables)? 如何仅使用数据表中的现有数据重绘使用服务器端处理的数据表? - How to redraw a Datatable that uses server side processing using only the existing data in the datatable? 如何为数据表服务器端处理返回JSON对象 - How to return JSON object for datatables server side processing 具有服务器端处理的DataTable - DataTable with Server-side processing 如何在 PHP 中使用 DataTAable 进行服务器端处理? - How to do server-side processing using DataTAble in PHP? 如何将 DataTable 中的单个列搜索与服务器端处理一起使用? - How to use individual column searching in DataTable with server-side processing? 如何在Datatable Server Side处理中加载额外的Javascript? - How to load extra Javascript in Datatable Server Side processing? 如何使用服务器端处理和Scroller扩展刷新DataTable - How to refresh DataTable with server side processing and Scroller extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM