【发布时间】:2017-01-01 09:51:42
【问题描述】:
我一直在试图弄清楚如何对使用数据表服务器端处理返回的数据执行算术运算。这很容易使用客户端数据表执行,但如果使用服务器端处理,我该怎么做这。这是我的代码。
ProductController.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);
}
route.php
Route::get('datatables', 'Product\ProductController@index');
Route::get('postproductsdata', 'Product\ProductController@anyData');
javascript:
$('#table-prod-contents').DataTable({
processing: true,
serverSide: true,
ajax: $.fn.dataTable.pipeline( {
url: '{{ url("postproductsdata") }}',
pages: 6000 // number of pages to cache
} ),
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: 'quantity', name: 'quantity'},
{data: 'created_at', name: 'created_at'},
]
});
html:
<table id="table-prod-contents" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Category</th>
<th>Product Name</th>
<th>Description</th>
<th>Type</th>
<th>Unit</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Created at</th>
</tr>
</thead>
</table>
显示上面的代码,我想将价格乘以数量,然后将其显示在<th>Total</th> 中。我该怎么做?
【问题讨论】:
-
如何对返回的数据进行操作?
标签: php jquery datatables laravel-5.2