Getting label of saved state button
Getting label of saved state button
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();
console.log(currentStateName);
});
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
Answers
I updated your selector a bit to use what Datatables creates and it seems to work:
https://live.datatables.net/xesazapi/1/edit
Kevin
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: