order data but disable sorting

order data but disable sorting

dtarvindtarvin Posts: 7Questions: 2Answers: 0

Hi, I have a DataTable with several columns (I don't believe the titles or type of data in the column is important). I want to order it by one of the columns, say column 4. When I put in

"order": [ 4, 'desc' ]

It does a wonderful job of putting the data in the column in descending order.

The problem is I also want to disable the user's ability to sort in a different way by clicking on the column title. Right now, if the user clicks on, say, column 1, the table will reorder according to that column's data and will no longer be ordered by column 4's data.

I tried adding the following command:

"ordering": false

I kept in the "order" field to sort by column 4. However, with the "ordering" field on there, the table will no longer sort by column 4, even though I kept that command in the code.

So, how do I sort data by a specific column and also disable the user's ability to sort any other way?

Thanks!

Answers

  • dtarvindtarvin Posts: 7Questions: 2Answers: 0

    A little more information: I tried putting
    "orderable": false
    under ColumnDefs. However, it only worked if I added every single column number as a target. Also, I had hidden columns 4 and 5 with a
    "visible": false,
    "targets": [4, 5].
    However, if I keep that on with the orderable: false then the orderable: false does not work and I can continue to order the data by all the columns. Yet I can't leave columns 4 and 5 visible.

  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916

    What you describe seems to work here:
    http://live.datatables.net/milupale/1/edit

    I put a second (duplicate) table below so you can see it is sorted by column 4.

    Maybe you have .a syntax error. Check you browser's console.

    Kevin

This discussion has been closed.