单击“刷新”按钮时出现问题,数据表未重新绘制数据,但我可以看到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": 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> 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()函数来重新加载dataTables。
但是它不起作用。我尝试了不同的方法。
您能告诉我这是什么问题吗?
答案 0 :(得分:0)
我能够解决我的问题。我使用的绘制值为1 (“ draw” => 1)
现在我已更改为“绘制” => intval($ _POST ['draw'])
echo json_encode(array('data' => $rows_json, "draw" =>intval($_POST['draw']), "recordsTotal" => $totalRecords, "recordsFiltered" => $totalRecords));
运行良好。