No sort my first column

No sort my first column

AlexolAlexol Posts: 11Questions: 4Answers: 0

I have a ranking of points

1 - Alex - 400
2 - John - 540
3 - Paul - 200

With order: [ [ 2,'desc']]

I get

2 - John - 540
1 - Alex - 400
3 - Paul - 200

But I don't want the 1st column to be sorted, I want

1 - John - 540
2 - Alex - 400
3 - Paul - 200

Is there a function with datatable? I searched, searched, but I didn't find. orderable : false is not my solution, I think...

Answers

  • AlexolAlexol Posts: 11Questions: 4Answers: 0

    Found a solution.

    https://datatables.net/examples/api/counter_columns.html

    But is there better way?

  • kthorngrenkthorngren Posts: 20,147Questions: 26Answers: 4,736

    Sounds like you want to start with order: [ [ 2,'desc']] to set the rank order. Then use the code in the example you linked to. But that example changes the counter column anytime you sort or search. I think you only want to run it once after the initial sort. In this case move that code inside initComplete.

    However that might not be what you want. If not then please provide more details:

    I have a ranking of points
    1 - Alex - 400
    2 - John - 540
    3 - Paul - 200

    How are the numbers in the first column generated originally? For example how does Alex get 1?

    Can you return the data from the server in the order you want, ie, points field order desc?

    Not sure if you want the ability to order the table or not (ordering: false). Datatables will display in the order returned if you use something like order: [],. You can use the combo of order: [], or order: [ [ 2,'desc']] and ordering: false to have a static table.

    You may be interested in the orderFixed option.

    Just some rambling thoughts on things you may want to consider doing.

    HTH,
    Kevin

This discussion has been closed.