Need sorting_asc on different column

Need sorting_asc on different column

Praful_21Praful_21 Posts: 3Questions: 1Answers: 0

Hey Community folks,
By default it gets attached to the first column <th>. I tried with ["order": [[3, "asc"]] ]. But an error return as typeerror c is undefined
I am attaching my code below. Let me know what is the solution.

 d_table.dataTable({
          "responsive": true,
          "iDisplayLength": 25,
          "bPaginate": true,
          // "order": [[3, "asc"]],
          "processing": true,
          "serverSide": true,
          "sPaginationType": "full_numbers",
          "bRetrieve": true,
          "deferLoading": 0,
          "columnDefs":[{
            "targets": 0,
            "render": function(data, type, row){
              var html = `<td class='selector-box'><input name='checkboxlist' value="${data.id}" type='checkbox'></td>`;
              return html;
            },
            "bSortable": true
          },
          {
              "targets": 1,
              "width": 100,
              "render": function(data, type, row){
                var html = data.id;
                return html;
              },
              "bSortable": false
          },
          {
              "targets": 2,
              "width": 100,
              "render": function(data, type, row){
                    var html = data.external_id;
                    $('#platform-name').html(data.platform.toLowerCase());
                    return html;
              },
              "bSortable": false
          },
            { "targets": 3,
              "width": 250,
              "render": function(data, type, row){
                var html;
                if(data.status == 'test_mode'){
                  html = `<span><h5 class='badge test-tag'>Test Mode</h5></span><a href="${data.link}">${data.name}</a>`;
                }
                else if(data.status == 'not live'){
                  html = `<span><h5 class='badge test-not-live'>Not Live</h5></span><a href="${data.link}">${data.name}</a>`;
                }
                else{
                  html = `<a href="${data.link}">${data.name}</a>`;
                }
                return html;
              },
              // "bSortable": true,
              "orderable": true
            },
            {
              "targets": 4,
              "width": 100,
              "render": function(data, type, row){
                var html;
                if(data.state == 1){
                  html = `<i class='fa fa-2x fa-toggle-on toggle-location-on' data-location="${data.id}" style='color: seagreen'></i></td>`;
                }else{
                  html = `<i class='fa fa-2x fa-toggle-off toggle-location-off' data-location="${data.id}"></i>`;
                }
                return html;
              },
              "bSortable": false
            }

          ],

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Yep, that's the correct usage for order so I'm surprised it's failing. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • Praful_21Praful_21 Posts: 3Questions: 1Answers: 0

    Hey Colin,
    First of all, thanks for the quick reply.
    I will provide with the testcase replica of the issue. In the meantime, Can you just look into the render function of targets: 3 of columnDefs. The data which is being rendered from the backend is in the form of a dict. So, to fill up the columns I have used separate values. Can you let me know on what basis it sorts? I am actually on a deadline here. So, that's why would really appreciate you lookinig into it as soon as possible.
    Thanks

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    The best guarantee of a quick response is to provide a test case, that way we can see the issue and will be able to debug it more effectively.

    Colin

  • Praful_21Praful_21 Posts: 3Questions: 1Answers: 0

    Hey Colin,
    I solved the issue. basically it was a mismatch between frontend and backend data requirements. The frontend was expecting something else when order was assigned on a different target. Figured it out. Anyways, Thanks buddy.
    Cheers.

This discussion has been closed.