DT_RowIndex not found but it exist

DT_RowIndex not found but it exist

reikireiki Posts: 46Questions: 11Answers: 0
edited February 2023 in Free community support
function setDataTableByTgl(tglA = null, tglB = null, departemenId = null, group = true, seperate = false, pisah = true, barangId = null, kodeMerk = null){
    setColumn(seperate)
      $('.tableCustom1').DataTable().destroy();
      var columns = [];
      columns.push(
          { data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false },
          { data: 'cabang', name: 'cabang',
            render: function (data, type, row){
              return '<a class = view2 data-tgla="'+tglA+'" data-tglb="'+tglA+'" data-departemenId ="'+row.departemenId+'" data-tgl = "'+row.tgl1+'" data-seperate = true data-allKaryawan = true data-kodemerk="'+kodeMerk+'" data-barangid="'+barangId+'" >'+data+'</a>';
            }
          },
      );
      for(var count = 0; count < 31; count++){
          columns.push(
            { data: count, name: count}
            );
      };
      columns.push(
        { data: 'score', name: 'score' }
      );
      $('.tableCustom1').DataTable({
        deferRender : true,
        scrollX: "800px",
        scrollY: "500px",
        scrollCollapse: true,
        paging: false,
        processing: true,
        serverSide: false,
        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 following ajax which work because i set orderable: false, searchable: false but i want it to be true for both so it can be sort but when i do that it will return error Uknown Column 'DT_RowIndex' but in my json there is 'DT_RowIndex' this only happen on transpose query , this is the query :

  $scoreboard = HistoryPenjualan::select(DB::raw('*'));
                              $count = [];                       
                                      $scoreboard->from(function($query) use ( $hariSama, $tglA, $tglB, $departemenId, $kodeMerk, $barangId ){
                                        $query ->selectRaw(DB::raw("DISTINCT DATE_FORMAT(`tgl`, '%Y-%m') as 'tgl1',`departemenId`, 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])
                                        ->where('departemenId', $departemenId)              
                                        ->groupBy('tgl1')
                                        ->from('history_penjualan');
                                      });   
                                      for ($j = 1; $j < 32; $j++){
                                          array_push($count, strval($j));   
                                      };                    
                              $scoreboard
                              ->get();

It only happen to that query where i transpose stuff from row to column other query works just fine without orderable: false, searchable: false, whats the cause of this ?

Does doing that query messed up datatables sorting and searching ?

Also iam using Yajrabox for the serverside on laravel

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    Can you show me the JSON response from the server please?

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    Already sent but it say the comment need to be approved first

  • reikireiki Posts: 46Questions: 11Answers: 0
    [
      {
        "0": "<a class = view data-tgla=\"2023-01-1\" data-tglb=\"2023-01-1\" data-departemenId =\"13\" data-tgl =\"2023-01-1\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >11,796</a>",
        "1": "<a class = view data-tgla=\"2023-01-2\" data-tglb=\"2023-01-2\" data-departemenId =\"13\" data-tgl =\"2023-01-2\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >33,299</a>",
        "2": "<a class = view data-tgla=\"2023-01-3\" data-tglb=\"2023-01-3\" data-departemenId =\"13\" data-tgl =\"2023-01-3\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >22,901</a>",
        "3": "<a class = view data-tgla=\"2023-01-4\" data-tglb=\"2023-01-4\" data-departemenId =\"13\" data-tgl =\"2023-01-4\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >20,983</a>",
        "4": "<a class = view data-tgla=\"2023-01-5\" data-tglb=\"2023-01-5\" data-departemenId =\"13\" data-tgl =\"2023-01-5\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >34,938</a>",
        "5": "<a class = view data-tgla=\"2023-01-6\" data-tglb=\"2023-01-6\" data-departemenId =\"13\" data-tgl =\"2023-01-6\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >33,541</a>",
        "6": "<a class = view data-tgla=\"2023-01-7\" data-tglb=\"2023-01-7\" data-departemenId =\"13\" data-tgl =\"2023-01-7\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >36,101</a>",
        "7": "<a class = view data-tgla=\"2023-01-8\" data-tglb=\"2023-01-8\" data-departemenId =\"13\" data-tgl =\"2023-01-8\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >51,473</a>",
        "8": "<a class = view data-tgla=\"2023-01-9\" data-tglb=\"2023-01-9\" data-departemenId =\"13\" data-tgl =\"2023-01-9\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >51,035</a>",
        "9": "<a class = view data-tgla=\"2023-01-10\" data-tglb=\"2023-01-10\" data-departemenId =\"13\" data-tgl =\"2023-01-10\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >41,671</a>",
        "10": "<a class = view data-tgla=\"2023-01-11\" data-tglb=\"2023-01-11\" data-departemenId =\"13\" data-tgl =\"2023-01-11\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >43,915</a>",
        "11": "<a class = view data-tgla=\"2023-01-12\" data-tglb=\"2023-01-12\" data-departemenId =\"13\" data-tgl =\"2023-01-12\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >44,832</a>",
        "12": "<a class = view data-tgla=\"2023-01-13\" data-tglb=\"2023-01-13\" data-departemenId =\"13\" data-tgl =\"2023-01-13\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >32,951</a>",
        "13": "<a class = view data-tgla=\"2023-01-14\" data-tglb=\"2023-01-14\" data-departemenId =\"13\" data-tgl =\"2023-01-14\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >27,496</a>",
        "14": "<a class = view data-tgla=\"2023-01-15\" data-tglb=\"2023-01-15\" data-departemenId =\"13\" data-tgl =\"2023-01-15\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >22,838</a>",
        "15": "<a class = view data-tgla=\"2023-01-16\" data-tglb=\"2023-01-16\" data-departemenId =\"13\" data-tgl =\"2023-01-16\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >42,994</a>",
        "16": "<a class = view data-tgla=\"2023-01-17\" data-tglb=\"2023-01-17\" data-departemenId =\"13\" data-tgl =\"2023-01-17\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >37,916</a>",
        "17": "<a class = view data-tgla=\"2023-01-18\" data-tglb=\"2023-01-18\" data-departemenId =\"13\" data-tgl =\"2023-01-18\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >46,025</a>",
        "18": "<a class = view data-tgla=\"2023-01-19\" data-tglb=\"2023-01-19\" data-departemenId =\"13\" data-tgl =\"2023-01-19\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >46,970</a>",
        "19": "<a class = view data-tgla=\"2023-01-20\" data-tglb=\"2023-01-20\" data-departemenId =\"13\" data-tgl =\"2023-01-20\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >45,718</a>",
        "20": "<a class = view data-tgla=\"2023-01-21\" data-tglb=\"2023-01-21\" data-departemenId =\"13\" data-tgl =\"2023-01-21\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >41,476</a>",
        "21": "<a class = view data-tgla=\"2023-01-22\" data-tglb=\"2023-01-22\" data-departemenId =\"13\" data-tgl =\"2023-01-22\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >32,524</a>",
        "22": "<a class = view data-tgla=\"2023-01-23\" data-tglb=\"2023-01-23\" data-departemenId =\"13\" data-tgl =\"2023-01-23\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >35,233</a>",
        "23": "<a class = view data-tgla=\"2023-01-24\" data-tglb=\"2023-01-24\" data-departemenId =\"13\" data-tgl =\"2023-01-24\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >36,713</a>",
        "24": "<a class = view data-tgla=\"2023-01-25\" data-tglb=\"2023-01-25\" data-departemenId =\"13\" data-tgl =\"2023-01-25\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >34,429</a>",
        "25": "<a class = view data-tgla=\"2023-01-26\" data-tglb=\"2023-01-26\" data-departemenId =\"13\" data-tgl =\"2023-01-26\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >43,265</a>",
        "26": "<a class = view data-tgla=\"2023-01-27\" data-tglb=\"2023-01-27\" data-departemenId =\"13\" data-tgl =\"2023-01-27\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >41,420</a>",
        "27": "<a class = view data-tgla=\"2023-01-28\" data-tglb=\"2023-01-28\" data-departemenId =\"13\" data-tgl =\"2023-01-28\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >35,216</a>",
        "28": "<a class = view data-tgla=\"2023-01-29\" data-tglb=\"2023-01-29\" data-departemenId =\"13\" data-tgl =\"2023-01-29\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >43,236</a>",
        "29": "<a class = view data-tgla=\"2023-01-30\" data-tglb=\"2023-01-30\" data-departemenId =\"13\" data-tgl =\"2023-01-30\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >79,600</a>",
        "30": "<a class = view data-tgla=\"2023-01-31\" data-tglb=\"2023-01-31\" data-departemenId =\"13\" data-tgl =\"2023-01-31\" data-group =\"false\" data-seperate = true data-allkaryawan = \"false\" data-kodemerk=\"\" data-barangid=\"\" >0</a>",
        "tgl1": "2023-01",
        "departemenId": 13,
        "kodeSales": "1522",
        "totalScore": "1152505",
        "Hari0": "11796",
        "Hari1": "33299",
        "Hari2": "22901",
        "Hari3": "20983",
        "Hari4": "34938",
        "Hari5": "33541",
        "Hari6": "36101",
        "Hari7": "51473",
        "Hari8": "51035",
        "Hari9": "41671",
        "Hari10": "43915",
        "Hari11": "44832",
        "Hari12": "32951",
        "Hari13": "27496",
        "Hari14": "22838",
        "Hari15": "42994",
        "Hari16": "37916",
        "Hari17": "46025",
        "Hari18": "46970",
        "Hari19": "45718",
        "Hari20": "41476",
        "Hari21": "32524",
        "Hari22": "35233",
        "Hari23": "36713",
        "Hari24": "34429",
        "Hari25": "43265",
        "Hari26": "41420",
        "Hari27": "35216",
        "Hari28": "43236",
        "Hari29": "79600",
        "Hari30": null,
        "action": "<button data-tgla=\"2023-01-01\" data-tglb=\"2023-01-31\" data-departemenid=\"13\"data-tgl=\"\"\" data-group=\"false\" data-seperate=\"true\" data-kodemerk=\"\" data-barangid=\"\" data-allkaryawan=\"false\" class=\"btn btn-success btn-sm view\"><i class=\"fa fa-eye\"></i></button>",
        "karyawan": null,
        "cabang": "CW1 - Citra Warna 1 :  January 2023",
        "score": "1,152,505<br>\r\n  <div class=\"progress\">\r\n    <div class=\"progress-bar progress-bar-striped progress-bar-animated bg-warning\" role=\"progressbar\" aria-valuenow=\"100\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 49.420528061948%\">\r\n    </div>\r\n  </div>\r\n  ",
        "DT_RowIndex": 1
      },
    ]
    

    this is one of the Response from JSON as you can see there is DT_RowIndex i got 41 other and all has DT_RowIndex with different number

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    Thanks! That does look like it should be okay. I'm afraid I'm going to need more information. Are you able to give me a link to the page so I can debug it please? If that isn't possible, can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    https://debug.datatables.net/asuvaz

    but idk why its not found

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    For data security only I can view the uploads.

    Interestingly there appears to be an issue displaying those results. I'll look into it and get back to you - although it might be tomorrow before I can do that now. Sorry.

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    I appriciate your help allan, i can wait. i like datatables because of the simplicity and customization you can do it help me alot + the forum is somewhat active too

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    I've managed to get the debugger showing me what I need to know again. Phew.

    This is the SQL that the code is running:

    select 
      * 
    from 
      (
        select 
          DISTINCT DATE_FORMAT(`tgl`, '%Y-%m') as 'tgl1', 
          `departemenId`, 
          `kodeSales`, 
          SUM(score) as totalScore, 
          (
            SUM(
              CASE WHEN tgl IN ('2023-01-01') THEN score END
            )
          -- ... 
          (
            SUM(
              CASE WHEN tgl IN ('2023-01-31') THEN score END
            )
          ) AS 'Hari30' 
        from 
          `history_penjualan` 
        where 
          `tgl` between 2023 - 01 - 01 
          and 2023 - 01 - 31 
        group by 
          `tgl1`, 
          `departemenId`
      ) as `` 
    order by 
      `DT_RowIndex` desc 
    limit 
      10 offset 0
    )
    

    What it doesn't like is order by DT_RowIndex desc. That doesn't exist in the database. I can't see in the above code where it would be defined if it isn't in the database - I can't even see where the select for it is - is that in the library code or something?

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    Interesting, i use yajra own function to create DT_RowIndex using the addIndexColumn(), https://yajrabox.com/docs/laravel-datatables/10.0/index-column#main-content the link for it. What i still dont understand is why only query like that where i transpose stuff that it doesnt recognize all "normal" query is fine

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin
    Answer ✓

    I honestly couldn't say - I'm not familiar with that code I'm afraid.

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0

    ahh okay no worry thanks for the help

Sign In or Register to comment.