Skip to content

How to preserve state between sorts? #307

@akinuri

Description

@akinuri

I have a simple table. I want to do multi-column sorting. I don't want to use shift+click. If I manually sort a column (via UI headers), and then sort another, this should count as a multi-column sort. However, that's not the case. Each sort seems to be applied to the initial sort state of the table and then rendered on the screen. That's not what I'd expect. On top of this, there doesn't seem to be a way around this.

I tried a few solutions (with the help of ChatGPT, since I'm new to this tool) and none worked. Finally, I tried to destroy the instance after a sort, and then reinitialize with the new state, however, when the instance is destroyed, the sort state is reverted back to the original state, so it didn't work.

Is there no way to do this? Why isn't the table itself used as the source of truth? Why isn't there a way to specify the source?

My setup in case it matters:

myDataTable = new DataTable(table, {
    paging: false,
    searching: false,
    info: false,
    columnDefs: [
        { orderable: false, targets: 0 },
        { orderSequence: ["asc", "desc"], targets: `_all` },
        {
            targets: 4,
            render: dtRenderRangeCell,
        },
        {
            targets: 7,
            render: dtRenderRangeCell,
        },
    ],
    order: [],
});

I hope I'm not overlooking anything as I'm frustrated atm :)


In regard to the issue note, I wouldn't want to sign up on the site/forum of every tool I use to give feedback, etc. It'd be too tedious. But I can be expected to do it on GitHub, since this is "the hub".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions