我很困惑使用ajax的laravel分页结果
<a style="float:right;margin-top:23px" class="btn btn-md btn-primary" type="button" id="filter"><i class="fa fa-filter"></i> Filter</a>
ajax代码:https://imgur.com/1lXtlgY
$("#filter").click(function(){
$.ajax({
type: "GET",
url: "{{url('/admin/penjualan_per_periode/penjualan')}}",
cache: false,
data: {'daterange': $("#daterange").val(),'customer': $("#customer").val(),'code_product': $("#code_product").val(),'status': $("#status").val()},
beforeSend: function(){
$('#table-result').empty();
$('.loading').show();
},
success: function(result){
$('.loading').hide();
$('#table-result').html(result);
}
});
});
public function getPenjualan() {
$time = array_map('trim',explode('-', g('daterange')));
$startDate = $time[0];
$endDate = $time[1];
$sd = explode('/', $startDate);
$ed = explode('/', $endDate);
$newStartDate = $sd[0].'-'.$sd[1].'-'.$sd[2].' 00:00:00';
$newEndDate = $ed[0].'-'.$ed[1].'-'.$ed[2].' 00:00:00';
$content = '
<table class="table">
<tr>
<th>DATE</th>
<th>ORDER ID</th>
<th>CUSTOMER</th>
<th>CODE</th>
<th>NAME</th>
<th>STATUS</th>
<th>PRICE</th>
<th>QTY</th>
<th>TOTAL PRICE</th>
</tr>
';
$orderItem = DB::table('order_item')
->select('id_order','id_product','created_at')
->whereBetween('created_at', [$newStartDate,$newEndDate])
->orderBy('created_at', 'desc')
->paginate(5);
for($i=0; $i<count($orderItem); $i++) {
$order = DB::table('order_item')
->join('order','order_item.id_order','=','order.id')
->join('order_status','order_item.id_order','=','order_status.id_order')
->join('product','order_item.id_product','=','product.id')
->where(['order.id'=>$orderItem[$i]->id_order, 'order_status.id_order'=>$orderItem[$i]->id_order, 'product.id'=>$orderItem[$i]->id_product])
->select('order.id_customer as id_customer','order.id as id_order','order_status.status as status','order_item.qty as qty_product','order_item.sub_total as sub_total_product','product.code as code_product','product.name as name_product','product.price as price_product','order_item.created_at')
->first();
$customer = DB::table('customer')->select('full_name')->where('id',$order->id_customer)->first();
$content.= '
<tr>
<td>'.Carbon::parse($order->created_at)->format('d-M-Y').'</td>
<td>'.$order->id_order.'</td>
<td>'.$customer->full_name.'</td>
<td>'.$order->code_product.'</td>
<td>'.$order->name_product.'</td>
<td>'.$order->status.'</td>
<td>Rp'.number_format($order->price_product).'</td>
<td>'.$order->qty_product.'</td>
<td>Rp'.number_format($order->sub_total_product).'</td>
</tr>
';
}
$content .= '</table>';
return $content;
控制器:
1. https://imgur.com/tj0bZwt
2。https://imgur.com/DDusf10
3. https://imgur.com/TslGzUb
数据被ajax结果覆盖div#table-result,我如何对数据结果进行分页并显示