Can I use different orderSequences with orderData?

Can I use different orderSequences with orderData?

FatalBulletHitFatalBulletHit Posts: 4Questions: 1Answers: 0
edited April 2020 in Free community support

I have a few columns in my table whose default ordering direction is orderSequence: [ "desc", "asc" ]. Those columns contain cells which are mostly either empty or have a low numeric value (e.g. 1 or 2), so I'm making use of orderData to additionally sort the results by name, however, the column with the names is now sorted descending as well.

I thought something like orderData: [[ 2, "desc"], [ 1, "asc"]] might work, but I then found this answer were allan says, that this is currently not possible.

This answer is more than 2 years old, tho, so have there been any changes or are there any planned at all?
And if there haven't been, what could be a possible workaround or hack?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416

    never used "orderData" before... Data Tables has so many features ... but I just found this in my code (excerpt of one of my data table definitions).

    If you just want your Data Table to be ordered by column two descending and by column one ascending then take a look at "order" below :smile: if not: ignore this post.

    columnDefs: [
        {targets: [0, 1, 2, 3, 4], searchable: false}
    ],
    order: [[ 2, 'desc' ], [ 1, 'desc' ]],
    select: {
        style: 'single'
    },            
    buttons: [
        {   extend: "create", editor: editor, className: "someClass" },
        {   extend: "edit",   editor: editor, className: "same" },
        {   extend: "remove", editor: editor, className: "whatever" },
                    "colvis"
    ]
    
  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922

    This answer is more than 2 years old, tho, so have there been any changes or are there any planned at all?

    I doubt there have been changes to this.

    And if there haven't been, what could be a possible workaround or hack?

    Please provide a simple test case showing an example of the data you have so we can get a better idea of how to help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • FatalBulletHitFatalBulletHit Posts: 4Questions: 1Answers: 0
    edited April 2020

    Correct me if I'm wrong, but the order option is only executed at the initialization of the table and that's not what I'm searching for.

    The issue is that when sorting the 2nd column, its orderSequence overrules the one of the 1st column.

    Here's an example:
    http://live.datatables.net/besuzoru/1/edit?js,output

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416

    Ok, and what is your use case? I mean I have a use case which implies that I need to apply a completely different sort order exporting data to Excel than in my data table displayed to the user. If you have something similar I might be able to help you out.

  • kthorngrenkthorngren Posts: 21,170Questions: 26Answers: 4,922
    Answer ✓

    I think the test case helped to understand. See this example:
    http://live.datatables.net/besuzoru/2/edit

    Is that the effect you are looking for? It uses Otrhogonal Data to manipulate the sort operation. The only odd thing is the sorting arrows point in the wrong direction. If this is what you want hen maybe a sorting plugin is needed to make it work properly. I don't have a quick example at the moment.

    Kevin

  • FatalBulletHitFatalBulletHit Posts: 4Questions: 1Answers: 0

    If you have something similar I might be able to help you out.

    Thanks, but I think kthorngren's answer should do the job, only thing I still need to figure out is how to make the icon appear properly. :smile:

    http://live.datatables.net/besuzoru/2/edit

    This is quite nice, I was trying to change the icons accordingly when sorting the 2nd column, but it only changes the icon of the 1st column and I can't change it back either:
    http://live.datatables.net/besuzoru/3/edit?js,output

    Any ideas?

  • FatalBulletHitFatalBulletHit Posts: 4Questions: 1Answers: 0

    Edit:
    Note, that the 1st column is switching between ascending and descending, which it ideally should not. I tried something but I feel like I'm just messing with the wrong column:
    http://live.datatables.net/boxopuyo/1/

    Btw, I've no idea of JavaScript, literally looked into it the first time yesterday and I'm pretty new to HTML and CSS, as well. :#

This discussion has been closed.