Ordering sequence plugin assign class

Ordering sequence plugin assign class

Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

Is there an easy way to allow the developer to assign a class for orderNumbers? I know the default is dt-order-number, but for some DataTables I would like to define the class to be dt-order-number-top when the DataTable has multiple rows for a header. I would then define the css for dt-order-number-top

Otherwise the default class dt-order-number will be used.

Instead of:
orderNumbers: true

Something like:
orderNumbers: {className: 'dt-order-number-top'}

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Not at the moment - it is hard coded without a configuration option I'm afraid.

    Good idea for an enhancement though, I'd happy take a PR for that.

    Allan

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

    I will attempt a PR, haven't done one in a while

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

    Trying to look through other code to see how you handled additional settings for a feature. Couldn't find any in my quick search.

    Not sure if this is the standard you are looking for:

    Original Code:

    /** Remove all existing indicators */
    function remove(table) {
        $('span.dt-order-number', table.table().header()).remove();
    }
    

    Modified code:

    /** Remove all existing indicators */
    function remove(table) {
        var className = (table.settings()[0].oInit.orderNumbers.className) ? table.settings()[0].oInit.orderNumbers.className : 'dt-order-number';
        $('span.' + className, table.table().header()).remove();
    }
    

    I have also made a similar change to the
    function draw(table) {}

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    init() will get you the initialisation object without needing to hit the settings object. It'd be worth adding a check for orderNumbers being defined on the object as well before using it, but aside from that, yeah, I think looks good - nice one.

    Allan

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

    Got it so like:

    function remove(table) {
        let className = (table.init().orderNumbers && table.init().orderNumbers.className) ? table.init().orderNumbers.className : 'dt-order-number';
        $('span.' + className, table.table().header()).remove();
    }
    

    If this is general what you are looking for, I will try to put together a pull request.

    Is there any documentation I need to take care of?
    I could also post a comment to your blog about the feature and the change made.

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

    I see in the init.dt the feature is enabled based on settings or defaults.

    var enable = settings.oInit.orderNumbers || DataTable.defaults.orderNumbers;

    Do I need to worry about defaults when checking for the className?

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    For completeness you could add a bit about the default. You'd need to make a default object available though:

    DataTable.defaults.orderNumbers = {
      className: 'dt-order-number'
    };
    

    I'd take the PR with or without that to be honest.

    Documentation - currently no. That is something I really need to sort out for the plugins. Possibly adding an example showing the option in use would be the way to do it at the moment.

    Allan

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1

    I couldn't find code in any other feature for the above recommendation for completeness. So I will let you educate me by adding it.

    I would be happy to add an example but need to determine how to in the orderNumbers/examples folder.

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    Thanks for the PR! I've made this commit to allow the defaults to work with an object based initialisation, and also add an example.

    Allan

  • Wooly65Wooly65 Posts: 85Questions: 25Answers: 1
    edited August 27

    Sorry I couldn't make the correct changes to add the new option, causing you to refactor. I will definitely used this plug-in as an example for any future PRs.

    Thanks for the inclusion of the new option.

    What Plugin category are you going to add this to?

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    No worries - the plugins are constantly evolving and this one probably has better default handling than the others now. I'll be using it as a template as well!

    Its a feature plugin, which again is an evolving part of the site. I need to spend some time working on the documentation and presentation of the plugins.

    Allan

Sign In or Register to comment.