Laravel 5.2: 重绘 DataTable 无效但 ajax.reload() 有效

Laravel 5.2: Redraw DataTable is not working But ajax.reload() is working

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

PHP、MYSQL、LARAVEL 5.2、数据表 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": false },
            { "data": "qty", "orderable": false },
            { "data": "sellingPrice", "orderable": false },
            { "data": "amount", "orderable": false }
                    ],
        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);
}

输出

`{"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));

当我更新数量和价格时,它会存储在数据库中。然后我将 fnDoOrderProductsReloadSearch() 函数重新加载数据表。

但是它不起作用。我尝试了不同的方法..

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

我可以解决我的问题。我使用绘制值作为 1 ("draw" => 1)

现在我改成了"draw" => intval( $_POST['draw'] )

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

运行良好。