Display a label of the current active state

Display a label of the current active state

CT General AssemblyCT General Assembly Posts: 20Questions: 3Answers: 1

Regarding this example, https://datatables.net/extensions/staterestore/examples/customisation/activeLabel.html

Is there a way to get the "current" state rather than just all of the Active States to be able to display that?

This question has an accepted answers - jump to answer

Answers

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

    You can use state() to get the current state object of the DataTable. Is that what you mean?

    Allan

  • CT General AssemblyCT General Assembly Posts: 20Questions: 3Answers: 1
    edited November 19

    Does that give the name of it?

    We have the states implemented and are letting the users rename them and so on. They want to see the name of the current state that they have chosen.

  • CT General AssemblyCT General Assembly Posts: 20Questions: 3Answers: 1
    edited November 19

    I ended up figuring it out and am doing it this way:

    DataTable.ext.buttons.stateRestore.action = function (e, dt, node, config) {
    config._stateRestore.load(config._stateRestore.s.identifier);
    $('.dataTables_info').html($('.dataTables_info').html().toString() + ' Current View: ' +config._stateRestore.s.identifier);
    };

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

    Oh I see what you mean - I thought you were looking for the state at any point, regardless of if it has been restored or not.

    Yes, it isn't ideal and I think the StateRestore API could be improved for a few things like this.

    Good to hear you found a solution for now.

    Allan

Sign In or Register to comment.