Pagination server side causes Exception Message:\n\nDivision by zero
Pagination server side causes Exception Message:\n\nDivision by zero
reiki
Posts: 46Questions: 11Answers: 0
my ajax :
$('.tableCustom1').DataTable({
deferRender : true,
scrollX: "800px",
scrollCollapse: true,
deferRender: true,
paging : true,
lengthChange: false,
processing: true,
serverSide: true,
fixedColumns: {
left: 0,
right: 1
},
order : [],
ajax: {
url: "{{ route('scoreboard.viewByTgl') }}",
type: "GET",
data: {
tglA: tglA,
tglB: tglB,
departemenId: departemenId,
group: group,
seperate: seperate,
pisah: pisah,
barangId: barangId,
kodeMerk: kodeMerk,
},
},
columns: columns
});
}
my query :
$columns = array(
// datatable column index => database column name
0 =>'DT_RowIndex',
1 => 'DepartemenId',
33 => 'totalScore',
);
$scoreboard = HistoryPenjualan::select(DB::raw('*'));
$scoreboard->from(function($query) use ( $hariSama, $tglA, $tglB, $kodeMerk, $barangId, $orderColumn, $orderDir, $columns, $length ){
$query ->selectRaw(DB::raw("DISTINCT DATE_FORMAT(`tgl`, '%Y-%m') as 'tgl1',`departemenId`, `kodeSales`, SUM(score) as totalScore"));
for ($j = 0; $j < 31; $j++){
$dateFormat = $hariSama[$j];
$query->selectRaw(DB::raw("(SUM(CASE WHEN tgl IN ($dateFormat) THEN score END) ) AS 'Hari$j' "));
};
if (!empty($kodeMerk)){
$query->whereRaw(DB::raw("EXISTS (SELECT * FROM `barang` where `history_penjualan`.`barangId` = `barang`.`id` and `kodeMerk` = '$kodeMerk')"));
}
if (!empty($barangId)){
$query->where('barangId', $barangId);
}
$query->whereBetween('tgl', [$tglA, $tglB])
->groupBy('tgl1')
->groupBy('departemenId');
if(!empty($orderDir) && $orderColumn != 0){
$query->orderBy($columns[$orderColumn],$orderDir);
}
$query->from('history_penjualan');
});
if (!empty($length)){
$scoreboard->skip($start)->take($length);
}
$scoreboard->get();
When i tried to go to page 2 it return error "Exception Message:\n\nDivision by zero"
, what cause this ? because page 1 of table is fine and not using paging is fine also
This discussion has been closed.
Answers
Closing as duplicated here.