Change background color if button is currently active
Change background color if button is currently active
Tamras
Posts: 12Questions: 5Answers: 0
I added custom buttons to filter my list, is there a way to change the background color of the button associated with the current filter? With the following code, if user clicks on 'A' button, I want that button to display in different background color and then revert if another button is clicked?
dataTableExample = $('#tableAcronyms').DataTable({
"pageLength": 25, //number of rows to display per page
"searching": true,
"order":[0, "asc"],
"paging": true,
"info": true,
"dom": "Bfrtip",
"buttons": [
{
"text": "A",
"action": function (e, dt, node, config) {
regExSearch = '^' + 'A';
dt.column(0).search(regExSearch, true, false).draw();
}
},
{
"text": "B",
"action": function (e, dt, node, config) {
regExSearch = '^' + 'B';
dt.column(0).search(regExSearch, true, false).draw();
}
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
In your action, node should be the dom button clicked so remove the class that sets the color from all buttons then add the color class to that button(node)
@Bindrid2 Thanks. I just need to figure out how to do what you just said. I'll read through the buttons page, maybe it'll explain it to me how to remove the class.
@Tamras here is something for you to play with
https://jsbin.com/micejaw/edit?html,css,js,output
@Bindrid2 thank you!! I just made the font and border change color rather than background.
CSS: