Disabling sorting on server side

Disabling sorting on server side

reikireiki Posts: 46Questions: 11Answers: 0

i got a server side set to true, but the sorting for column it still use datatable one , how do i disable it and let me control it ?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    When you say, let you control it, do you mean by setting the default sort order? If that is the case, then you need to set order. If you want to disable ordering altogether, set ordering to false,

    Colin

  • reikireiki Posts: 46Questions: 11Answers: 0

    i mean by that is not from inisialization table when it click the header it will sort but its using datatables one

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Setting ordering to false will disable Datatables sorting capabilities.

    Kevin

  • reikireiki Posts: 46Questions: 11Answers: 0

    but if set it to false then i user cant click the header and datatable dont send the information for what column is it and what order isnt it ?

  • reikireiki Posts: 46Questions: 11Answers: 0

    if i set orderingto false then i would not get this in the json :

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

    That is correct. We thought you wanted to disable sorting? I don't really understand what you are looking for if you want to disable sorting, but also keep it sending the order parameters?

    Allan

  • reikireiki Posts: 46Questions: 11Answers: 0
    edited February 2023

    i want only to disable sorting by the datatables, right now if i press the header the sorting is done by datatables (i assume the datatables add ORDER BY to my query automatically) , now i want to turn that off but still send the information what column user click + the order. cause i wanna reorder them on dataSrc its like specific case

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    i assume the datatables add ORDER BY to my query automatically

    If you are using a Datatables supplied server script then yes I believe this is the case. You can change this to meet your requirements. What are you using for your server side processing script?

    cause i wanna reorder them on dataSrc its like specific case

    Please clarify what you mean by dataSrc. Are you referring to ajax.dataSrc?

    Kevin

  • reikireiki Posts: 46Questions: 11Answers: 0

    yes i was refering to the ajax.dataSrc, basically in my dataSrc i manipulate the data alot that changing the order of json from ORDER BY query mess it up. for the server side iam using yajrabox and using laravel framework.

  • reikireiki Posts: 46Questions: 11Answers: 0
    dataSrc : function(json){
                function progress(score, max){
                  var nilai = (score / max) * 100;
                  if(nilai <= 25){
                    var warna = 'danger';
                  }else if(nilai <= 50){
                    var warna = 'warning';
                  }else if(nilai <= 75){
                    var warna = 'success';
                  }else if(nilai <= 100){
                    var warna = 'primary';
                  }
                  return '<div class="progress"><div class="progress-bar progress-bar-striped progress-bar-animated bg-'+warna+'" role="progressbar" aria-valuenow="9" aria-valuemin="0" aria-valuemax="9" style="width:'+nilai+'%"></div></div>';
                }
                var return_data = new Array();
                var count = 0;
                var index = 0;
                var maxScore = [];
                var maxIndex = 0;
                var arrayTemp = [];
                var temp = 0;
                var order = json.input.order[0]['dir'];
                var column = json.input.order[0]['column'];
                for (var i = 0; i < json.data.length-1; i++){
                  var tgl = json.data[i]['tgl'].slice(0,-3);
                  var tglD = json.data[i+1]['tgl'].slice(0,-3);
                  if (tgl != tglD){
                    arrayTemp[temp] = parseInt(json.data[i]['totalScore']);
                    maxScore[maxIndex] = arrayTemp.reduce((a, b) => a + b, 0);
                    maxIndex++;
                    temp = 0;
                    arrayTemp = [];
                  }else {
                    arrayTemp[temp] = parseInt(json.data[i]['totalScore']);
                    temp++;
                  }
                }
                var max = Math.max(...maxScore);
                do {
                  var arrayScore = [];
                  arrayScore[28] = 0;
                  arrayScore[29] = 0;
                  arrayScore[30] = 0;
                  var tgl1 = json.data[count]['tgl'];
                  var cabang = json.data[count]['cabang'].slice(0,-3);
                  var tglMonth = json.data[count]['tgl'].slice(0,-3);
                  var day = parseInt(json.data[count]['tgl'].slice(-2));
                  tglMonthDiff = tglMonth
                  var temp = 0;
                  var comparison = day-1;
                  while (tglMonth == tglMonthDiff ){
                    if (typeof json.data[count+1] === 'undefined'){
                      var day2 = parseInt(json.data[count]['tgl'].slice(-2));
                    } else {
                      var day2 = parseInt(json.data[count+1]['tgl'].slice(-2));
                    }
                    if (day+1 == day2 && order == 'asc'){
                      arrayScore[temp] = parseInt(json.data[count]['totalScore']);
                    }else if (day-1 == day2 && order == 'desc'){
                      arrayScore[comparison] = parseInt(json.data[count]['totalScore']);
                    }else if (order == 'asc'){
                      arrayScore[temp] = parseInt(json.data[count]['totalScore']);
                      temp++;
                      while(temp < day2-1){
                        arrayScore[temp] = 0;
                        temp++;
                      }
                      temp--;
                    } else if (order == 'desc'){
                      arrayScore[comparison] = parseInt(json.data[count]['totalScore']);
                      comparison--;
                      while(comparison > day2-1 ){
                        arrayScore[comparison] = 0;
                        comparison--;
                      }
                      comparison++
                    }
                    count++;
                    temp++;
                    comparison--;
                    console.log(arrayScore)
                    if (count < json.data.length){
                      tglMonthDiff = json.data[count]['tgl'].slice(0,-3);
                    } else {
                      break;
                    }
                  }
                  var totalScore = arrayScore.reduce((a, b) => a + b, 0);
                  var prog = progress(totalScore,max);
                  totalScore = totalScore.toLocaleString('en-US');
                  arrayScore.forEach(formatFunction);
                  function formatFunction(item, index, arr){
                    arr[index] = item.toLocaleString('en-US');
                  }
                  index++;
                    return_data.push({
                        '0' : arrayScore[0],
                        '1' : arrayScore[1],
                        '2' : arrayScore[2],
                        '3' : arrayScore[3],
                        '4' : arrayScore[4],
                        '5' : arrayScore[5],
                        '6' : arrayScore[6],
                        '7' : arrayScore[7],
                        '8' : arrayScore[8],
                        '9' : arrayScore[9],
                        '10' : arrayScore[10],
                        '11' : arrayScore[11],
                        '12' : arrayScore[12],
                        '13' : arrayScore[13],
                        '14' : arrayScore[14],
                        '15' : arrayScore[15],
                        '16' : arrayScore[16],
                        '17' : arrayScore[17],
                        '18' : arrayScore[18],
                        '19' : arrayScore[19],
                        '20' : arrayScore[20],
                        '21' : arrayScore[21],
                        '22' : arrayScore[22],
                        '23' : arrayScore[23],
                        '24' : arrayScore[24],
                        '25' : arrayScore[25],
                        '26' : arrayScore[26],
                        '27' : arrayScore[27],
                        '28' : arrayScore[28],
                        '29' : arrayScore[29],
                        '30' : arrayScore[30],
                        'DT_RowIndex': index,
                        'cabang' : cabang,
                        'score' : totalScore+'<br>'+prog,
                        'tgl1' : tglMonth,
                      })
                } while (count < json.data.length); 
                json.recordsTotal = return_data.length;
                json.recordsFiltered = return_data.length;
                json.draw = json.data.draw;
                // console.log(return_data);
                // if (order == 'desc'){
                //   return_data.sort((a,b) => b.DT_RowIndex - a.DT_RowIndex);
                // }
                return return_data;
              },
    

    this is my dataSrc yeah i know its long, basically iam transposing the json i get. Because i already tried transpose right from the query but it takes so long (because its process like 100k+ every query) thats why i proceed to use from datatables and js instead.

  • reikireiki Posts: 46Questions: 11Answers: 0

    i just need the datatables not to put ORDER BY to my query and just sent the order information so that i can process it in dataSrc instead (by reversing the order of the array so its simpler)

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited February 2023

    With server side processing enabled it is expected that the server script performs the sorting, searching and paging of the table data and returns only the rows to be displayed on the page. By default the page length is 10 rows. With server side processing the ajax.dataSrc should receive only 10 rows of data not 100k+ rows.

    i just need the datatables not to put ORDER BY to my query

    With server side processing enabled Datatables isn't doing this - it is just sending the parameters to the server. Your server side script (yajrabox) is building the query. If you want to change the behavior then you will need to refer to the yajrabox documentation or developers to find out how to change the sorting behavior as required.

    Kevin

  • reikireiki Posts: 46Questions: 11Answers: 0

    yeah the reason why its 100k+ row is that it suppose to transpose first so it get smaller but now the transpose is in dataSrc, okay i try to find the doc for yajra about ordering cause i cant find what causing the order by automatically

  • reikireiki Posts: 46Questions: 11Answers: 0

    theres also reason why i do this because enabling paging with the query (theres my other discussion about this here) return division by zero on page 2 and up and icant find the reason why its frustating

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    return division by zero on page 2 and up and icant find the reason why its frustating

    Guessing the problem is here?

    var nilai = (score / max) * 100;
    

    You will need to do some debugging to track the value of max to see why its zero, ie, this statement:

    var max = Math.max(...maxScore);
    

    Kevin

  • reikireiki Posts: 46Questions: 11Answers: 0

    ahh sorry forget to mention when enabling paging it was entirely different way i approach it not using any dataSrc, if you wanna see the code it was in my other discussion

Sign In or Register to comment.