Disable sorting of a column

Disable sorting of a column

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

How to disable sorting of a column and preventing it from being sorted even by sorting other columns. In other words, I just want it to stay fixed as it is.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    Sounds like columns.orderData could work. You would have a hidden column with an index then use columns.orderData to have the "fixed" column use the hidden column as the source for sorting. Additionally you might need to use orderFixed to keep the hidden column as always ordered thus keeping the "fixed" column always ordered..

    Let us know if this solution works for you.

    Kevin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    edited July 2018

    How would you create a hidden column that isn't linked to the actual table so not even the hidden column would be sorted? And also how would you link them? ^^
    Forgot to mention that this is what I have, that doesn't work.

                    "columnDefs": [
                        { 
                            "orderable": false, 
                            "targets": 0 
                        }
                    ],
                    "orderFixed": [0, 'asc'],
    

    Say column 0 is the hidden one, column 0 is the "fixed". This doesn't work either :

                    "columnDefs": [
                        { 
                            "orderable": false, 
                            "targets": 1
                        },
                        {
                            "targets": 0,
                            "visible": false,
                            "searchable": false
                        },
                        { 
                            "orderData": 1,           
                            "targets": 0
                        }
                    ],
                    "orderFixed": [0, 'asc'],
    
  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
    Answer ✓

    I found the answer in the docs, thanks !
    https://datatables.net/examples/api/counter_columns.html

This discussion has been closed.