Real-time sorting by number

Real-time sorting by number

AFL-alexandreAFL-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

Answers

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959

    The natural sorting plugin may work. If not you may be ale to modify it to support your string format.

    Kevin

  • AFL-alexandreAFL-alexandre Posts: 5Questions: 1Answers: 0

    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"?

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959

    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

  • rf1234rf1234 Posts: 3,004Questions: 87Answers: 421

    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

  • AFL-alexandreAFL-alexandre Posts: 5Questions: 1Answers: 0

    Thank you for your answers.

    I'm really sorry, I think it must be beyond my capabilities. I don't understand anything. :(

  • kthorngrenkthorngren Posts: 21,382Questions: 26Answers: 4,959
    edited March 2020

    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

  • AFL-alexandreAFL-alexandre Posts: 5Questions: 1Answers: 0
    edited April 2020

    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:

  • rf1234rf1234 Posts: 3,004Questions: 87Answers: 421
    Answer ✓

    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?

  • AFL-alexandreAFL-alexandre Posts: 5Questions: 1Answers: 0

    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.

  • rf1234rf1234 Posts: 3,004Questions: 87Answers: 421

    :/ :o :D :D :D

This discussion has been closed.