Laravel 5.2:Redraw DataTable无法正常工作但是ajax.reload()正在运行

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (55)

单击刷新按钮时我遇到了问题,Datatables没有重新绘制数据但我可以看到Json数组即将到来。

PHP,MYSQL,LARAVEL 5.2,DATATABLES 1.10

HTML

   <table id="tblOrderList" class="table table-bordered table-hover">
    <thead>
    <tr class="warning">
    <th>#</th>
    <th>Product Code</th>
    <th>Quantity</th>
    <th>Selling Price</th>
    <th>Amount</th>
    </tr>
    </thead>
</table>

JAVASCRIPT

$(function(){
    dataTableIdGenerate = $("#tblOrderList").DataTable({
        processing: true,
        serverSide: true,       
        deferRender: true,
        scrollX:true,
        cache: false,   
        sorting: false, 
        responsive: false,      
        paging: false,
        ordering:false,
        searching:false,
        info:false,
        processData:false,
        fixedHeader: {
            header: true,
            footer: false
        },
        columns: [
            { "data": "SNo", "orderable": false },
            { "data": "productCode", "orderable": true },
            { "data": "qty", "orderable": true },
            { "data": "sellingPrice", "orderable": false },
            { "data": "amount", "orderable": true }
                    ],
        ajax: {
            url: "{{ fnGenerateUrl('orders_list') }}",
            type: "POST",
            "data":{ 
                _token: "{{csrf_token()}}",
                parentid:"{{ $order->id }}"
            }
        },          
        "language": {
            "lengthMenu": "_MENU_",
            "emptyTable": "No data found!",
            "zeroRecords": "No matching data found",
            "sProcessing": '<i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;please wait...processing...',
        },
        buttons: [
            {
                text: 'Reload',
                action: function () {
                   // table.ajax.reload();
                    fnDoOrderProductsReloadSearch();
                }
            }
        ],
        "initComplete": function( settings, json ) {

        },
            });
});


function fnDoOrderProductsReloadSearch()
{
    $('#tblOrderList').DataTable().ajax.reload(null, false);

    //$("#tblOrderList").DataTable().ajax.reload(null, false);
    //$("#tblOrderList").DataTable().ajax.reload();

    //dataTableIdGenerate.ajax.reload();
    //dataTableIdGenerate.draw();

    //$("#tblOrderList").DataTable().rows().invalidate().draw();
    //$("#tblOrderList").ajax.reload();

    //$("#tblOrderList").DataTable().draw();
    //setTimeout(function(){$("#tblOrderList_processing").hide();}, 1000);
}

OUTPUT

`{"data":[{
    "SNo":1,
    "id":"61be1780-5106-11e9-9b13-39c7d14bdcc4",
    "productCode":"10515273","qty":"<input type=\"text\" name=\"productquantity61be1780-5106-11e9-9b13-39c7d14bdcc4\" id=\"productquantity61be1780-5106-11e9-9b13-39c7d14bdcc4\" value=\"2\" onchange=\"fnOrderProductEditQuantity('61be1780-5106-11e9-9b13-39c7d14bdcc4')\"  class=\"form-control\" size=\"8\" placeholder=\"Enter the qty\" maxlength=\"20\" autocomplete=\"off\" \/>",
    ]
    "sellingPrice":"<input type=\"text\" name=\"productsellingprice61be1780-5106-11e9-9b13-39c7d14bdcc4\" id=\"productsellingprice61be1780-5106-11e9-9b13-39c7d14bdcc4\" value=\"1000\" onchange=\"fnOrderProductEditSellingPrice('61be1780-5106-11e9-9b13-39c7d14bdcc4')\" class=\"form-control\" size=\"12\" placeholder=\"Enter the unitprice\" maxlength=\"20\" autocomplete=\"off\" \/>","amount":"2,000.00"}],
"draw":1,"recordsTotal":1,"recordsFiltered":1}`

在我的控制器中

     echo json_encode(array('data' => $rows_json, "draw" => 1, "recordsTotal" => $totalRecords, "recordsFiltered" => $totalRecords));

当我更新qty和Price时,它将存储在数据库中。然后我将fnDoOrderProductsReloadSearch()函数重新加载dataTables。

但它不起作用。我试过不同的方法..

你能告诉我这个问题是什么吗?

提问于
用户回答回答于

我能够解决我的问题。我使用绘制值为1 (“绘制”=> 1)

现在我已经改为“draw”=> intval($ _POST ['draw'])

   echo json_encode(array('data' => $rows_json, "draw" =>intval($_POST['draw']), "recordsTotal" => $totalRecords, "recordsFiltered" => $totalRecords));

它运作良好。

扫码关注云+社区

领取腾讯云代金券