ADD Order by id desc
ADD Order by id desc
orik3ll0
Posts: 36Questions: 12Answers: 2
Hello all.
I need to order table by id. ID is not shown in table, how can I add order by data from mysql? Say simply i need to select my table by this query "Select comun1,column2,...,column(N) from MY_TABLE order by ID desc". Where and how to do it?
Thank you for your reply and help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I would send back the data in the right order, then, in your datatable add order:[], that will keep the order from changing until a user clicks on a column
@bindrid Dear bindrid. Can you write me small example how to do it? I do not know how to do it by Editor
Try this, got to live.http://live.datatables.net/.net , it is a sandbox that Allen has set up for us to play in.
If you run the code as is, you will see it default to the first column in asc order.
Now change the code from
to
This will change the order column to the 3 column, asc.
now change it to
This will cause the order to be set in the order the data is fed to it. No column ordering icons will be set since no order is being set. In this case, it will be in the order that the html was created.
here is the documentation https://datatables.net/reference/option/order
@bindrid Dear Bindrid. Thank you for reply, somehow it is working. I need to "order by id desc" and i am adding "order:[[0,"desc"]]". But problem is that i did not add id to columns but I added it as primary key when generated datatable. Now it takes 0 as first column from datatble( not need column )
I do this with most all of my tables. The first column is the ID column but its hidden by Datatables using the following:
Then you should be able to use your order config.
Kevin
@kthorngren thank you!) It works now!)