Sorting by UK format column works only on first page

Sorting by UK format column works only on first page

andreasblueherandreasblueher Posts: 2Questions: 1Answers: 0
edited March 2020 in Free community support

Hello,

thank you for help. I've switched my date format from en-US values to en-UK recently. On the first page it's working as expected (nothing strange), but on any other page it's sorting en-US style again. Is there a simple way without moment.js to achieve sorting for different locales?

return jQuery(tableId).DataTable({
            "sort": true,
            "order": [[orderIndex, "asc"]],
            "lengthMenu": [10, 25, 50, 75, 100],
            "pageLength": 50,
            "dom": 'Bfrtip',
            "buttons": ['excelHtml5'],
            columnDefs: [
                {
                    type: 'numeric-comma', targets: currencyIndexes
                },
                {
                    type: 'date', targets: dateIndexes
                }
            ]
        });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    There's no reason why that should be the case. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    edited March 2020 Answer ✓

    Is there a simple way without moment.js to achieve sorting for different locales?

    The recommended way to sort datetime columns is discussed in this blog. It does use moment.js. Is there a reason you don't want to use moment.js?

    With this solution you wouldn't set the column type. Datatables automatically will determine this.

    Kevin

  • andreasblueherandreasblueher Posts: 2Questions: 1Answers: 0

    Thank you for your fast replies. Your answers made me realize a couple of things. I didn't try to separate the issue to detect the core and I didn't understand enough how DataTable work.

    A former colleague initially setup the datatables and it's time for me to recreate the setup, install a newer version of datatables and consider moment.js because there is no need to reinvent the wheel.

    Thanks, this basically resolves the question.

This discussion has been closed.