Get current sort order for particular column

Get current sort order for particular column

xtech_devxtech_dev Posts: 25Questions: 11Answers: 0

Hello,

Is there any way to receive column sort order inside render function?

I have a requirement to apply two different sorting rules: one for ascending and other descending sort order.

IT Man?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @xtech_dev ,

    columns.render would be no good for those, since the values are cached on first access, so if direction was changed, it wouldn't be picked reflected.

    What you need is to develop a sorting plugin - here, you can define different behaviour for ascending or descending. This page here has several already made - and this one here could be good to use as a template.

    Cheers,

    Colin

  • xtech_devxtech_dev Posts: 25Questions: 11Answers: 0
    edited February 2019

    Thanks for this clue, I will read the docs.

  • xtech_devxtech_dev Posts: 25Questions: 11Answers: 0

    Ok, got the idea - looks fine.

    Is there any way to specify sort/order extension explicitly as part of columns (https://datatables.net/reference/option/columns)?

    I have only seen something like "columnDefs": [{ "type": "numeric-comma", targets: 3 } ] but this seems to split column configuration into multiple places.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @xtech_dev ,

    Yep, it can go in either - see columns.type - the examples have both ways of declaring it.

    Cheers,

    Colin

  • xtech_devxtech_dev Posts: 25Questions: 11Answers: 0

    OK, type will point which sort function to use.

    But will it influence any other features,can i change it without consequences other than changing sort implementation?

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

    Hi @xtech_dev ,

    The type can also affect the filtering, but that's unlikely to have an effect (or you would've spotted it!). So yep, you're good to go :)

    Cheers,

    Colin

This discussion has been closed.