sorting_disabled class not initially applied when orderable is false

sorting_disabled class not initially applied when orderable is false

Loren MaxwellLoren Maxwell Posts: 382Questions: 93Answers: 10

Link to test case:

http://live.datatables.net/pomeyuzo/4/edit

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

1) Notice that the first column has orderable set to false, however an ordering icon is initially present anyway. The class sorting_disabled has not been applied.
2) If I click on that icon nothing happens.
3) If I click on any other ordering icon then sorting_disabled is applied to the first column header and the ordering icon disappears.

When the table is initially displayed the sorting_disabled class should be applied to any columns where orderable is set to false.

Replies

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited May 2020

    This is from the columns.orderable docs:

    Note that this option only affects the end user's ability to order a column. Developers are still able to order a column using the order option or the order() method if required.

    By default Datatables will order the first column. This is why you see the ordering icon. You can affect this with the order option if you want another column to be initially order or no order applied to the table. For example:
    http://live.datatables.net/pomeyuzo/5/edit

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 382Questions: 93Answers: 10
    edited May 2020

    Thanks, @kthorngren, I see that now.

    So maybe this isn't a bug as much as a request. I still think columns that aren't orderable should never have the ordering icon show.

    My first reaction to seeing the icon was that I must have written the code wrong and the column was still orderable. I was further confused when the ordering icon didn't work.

    So I imagine a visitor seeing the icon would think the column is orderable as well and then be similarly confused when it doesn't work and not really understanding why it was initially there or why it goes away if another column is ordered or why it never comes back.

    Just my take on it!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Yep, agreed, there is a long-standing fault for that, raised internally (DD-23 for my reference) a while back - see thread here. I've added this thread to it, and we'll report back here when it's progressed.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Interesting, I wouldn't consider this an issue. I would want the user to see the order state of the column even if they aren't able to order it. Especially if the column is programmatically ordered based on table interaction.

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 382Questions: 93Answers: 10

    Well, I don't necessarily disagree with Kevin either . . .

    Is it possible to maybe have a different icon for that?

    Or back in the neoclassical period before I used datatables*, I would make the currently sorted column a shade darker so a visitor could tell which column was being sorted on.

    I'd actually argue that's the best solution because if I'm sorting by a particular column I'm probably trying to draw the visitor's attention to it and with the darker shading it immediately stands out.


      • Me finding DataTables was the start of The Age of Enlightenment.
  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    That's a fair point. The shading happens by default for the ordered columns, so that's already there.

    Colin

  • Loren MaxwellLoren Maxwell Posts: 382Questions: 93Answers: 10

    The shading happens by default for the ordered columns, so that's already there.

    Unfortunately that's not for all styling. I'm using Bootstrap 4 and it doesn't shade the sorted column.

This discussion has been closed.