How to implement a custom sort in my use case?

How to implement a custom sort in my use case?

ambrosehundalambrosehundal Posts: 2Questions: 1Answers: 0

I have a table for which I am using datatables to sort. One of the table columns is called "status" and it has three possible values - pending, rejected and approved.

Right now I can sort by rejected and approved. I would like to have a custom sort where I could sort by "pending" . How should I go about this?

Answers

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

    Hi @ambrosehundal ,

    You could either use columns.render or create a custom sorting plugin,

    Cheers,

    Colin

  • ambrosehundalambrosehundal Posts: 2Questions: 1Answers: 0
    edited September 2019

    Hi Colin, would this still allow me to sort by "rejected" and "approved" along with sorting by "pending' all three?

    This is the code I used
    $(document).ready(function() {
      $('#sort_table').DataTable( {
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            "columns" : [
              { "data" : "status",
                "render" : "pending"
    
              }
            ]
      } );
    });
    

    I am not sure what I am doing wrong

    the column is called approval_status from the row that is coming from the db. My table column header is called "Status". Which one am I supposed to use?

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

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

    You would use the name in the JSON, which I suspect would be approval_status. 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

This discussion has been closed.