Getting label of saved state button

Getting label of saved state button

zecksteinzeckstein Posts: 16Questions: 6Answers: 0

I allow my users to create saved states with custom names. I'm trying to pull the custom name (label) of a saved state and put it in the dom as a title when they restore one of the saved states.

But, I can't seem to find where I could pull the label from. I tried to add a custom class to the saved states button and then do this:

$(document).on('click', '.wiz-dt-button.saved-views button > span', function() {
        currentStateName = $(this).text(); 

But I can't seem to get the selector right, or possibly the buttons are not in the dom at the right time or something.

Any tips here?

This question has an accepted answers - jump to answer


  • kthorngrenkthorngren Posts: 19,511Questions: 26Answers: 4,624
    Answer ✓

    I updated your selector a bit to use what Datatables creates and it seems to work:

     $('#example_wrapper').on('click', 'div.dt-button-split > button.dt-button', function() {
            currentStateName = $(this).text();


  • zecksteinzeckstein Posts: 16Questions: 6Answers: 0

    Thanks, that got me on the right track! But I needed it to be unique to clicks only on specific .dt-button-split elements related to the savedStates menu. Since the closest element I can add a unique class to for the SavedStates buttonset is the "parent" button, this is what ended up working:

    let currentStateName = ""; 
        $(document).on('click', 'div.dt-button-split > button.dt-button', function() {
            // Check if this button is related to 'saved-views'
            if ($(this).closest('.dt-button-collection').siblings('.saved-views').length) {
                currentStateName = $(this).text().trim();
Sign In or Register to comment.