Real-time sorting by number
Real-time sorting by number
AFL-alexandre
Posts: 5Questions: 1Answers: 0
Hello, first of all a big thank you for all the help on this site!
I have a question that will probably seem simple... But how do you make the table sort in real time according to a number? (1 à 5)
I would like him to always put the highest score (5) first.
Thank you in advance, and sorry for my English, I use a translator to help me.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The natural sorting plugin may work. If not you may be ale to modify it to support your string format.
Kevin
Thank you for your response.
I'm not very comfortable with anything in code.
Do I have to copy and paste the entire "plugin-code"?
You can use the CDN link where you load the other
.js
scripts, like this:<script src="https://cdn.datatables.net/plug-ins/1.10.20/sorting/natural.js"></script>
Kevin
Well if it is just regular sorting with unformatted numbers like 1 to 5 I don't think you need any additional plug in. It'll work just like alphabetical sorting.
You can set the initial order with an option:
https://datatables.net/reference/option/order
And you can reorder using the controls in the table header or the api:
https://datatables.net/reference/api/order()
If you want stuff like formatted number sorting or date sorting then you need a plugin because the regular sorting doesn't work.
Here is something more detailed on this:
https://stackoverflow.com/questions/53238318/html5-javascript-datatables-order-sort-of-columns/53238593#53238593
Thank you for your answers.
I'm really sorry, I think it must be beyond my capabilities. I don't understand anything.
It looks like the natural.js plugin and the other sorting string + numeric sorting plugins use the left most digits as part of the sorting algorithm. I made slight modification to the numString plugin to work with your format of
1 à 5
. Here is the example:http://live.datatables.net/qacunono/1/edit
EDIT: Here is the link for the docs to sorting plugins:
https://datatables.net/manual/plug-ins/sorting
Kevin
Hello, well I found my solution here : https://tablepress.org/extensions/table-row-order/
Here's the code:
[table id=1 row_order=sort row_order_sort_column=a row_order_sort_direction=ASC /]
So it works except that I use a ratings extension which I have a problem with, I'll explain.
To put the information I have to paste in the table:
[ratings id="499" results="true"], result for example 5.
The table classifies the id, so "499" and not the result "5".
I'll give you a picture of what's going on:
Looks like you are not using data tables but a product called table press. This forum is about data tables and Editor as far as I know.
@allan, are you guys taking care of table press as well?
Ohhh ok I'm really sorry so that's why I didn't understand the answers.
Sorry again and thank you for answering even though I was wrong.