Pagination server side doesnt show next page

Pagination server side doesnt show next page

reikireiki Posts: 46Questions: 11Answers: 0
edited February 2023 in Free community support

this might be because iam dumb or idk how to but :

$('.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
      });

i got this ajax and the query i use this :

$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();

its long but the point is i use skip and take there based on start and length the data tables give but when the table initialize it only show 1 page (theres 41 record) but only show 10 and it doesnt show next page or page 2 and so on :

iam using laravel with yajrabox as server side, do i have to change my query on how to handle paginate or what other ways to do it ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Where are $length and $start being defined?

    Also, if you are using server-side processing you need to return recordsTotal (see docs here) to tell DataTables how many rows there are in the table.

    You might need to ask yajra about this as it isn't software we produce or support.

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    hi allan, $length and $start was being defined to the datatables request (it was being defined before not in that specific code)

    For the recordsTotal yeah i already return that too yajra has function for that

  • reikireiki Posts: 46Questions: 11Answers: 0

    i found the problem its because theres 2 limit and offset, tried using only the datatables (so disable this code

    if (!empty($length)){
                          $scoreboard->skip($start)->take($length);
                        }
    

    datatable receive full records + there is next page and per page is 10 but like the other duplicate post it say error Division by zero but in my controller there is no division

  • reikireiki Posts: 46Questions: 11Answers: 0

    I suspect it has something to do with how the query works ? but the query it self doesnt have division

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    I'm afraid you'll need to ask Yajia about this - I haven't read through that code.

    Allan

Sign In or Register to comment.