How to filter the column with a button
How to filter the column with a button
Hi
I have added a button to select the same column name / category in and hide the unselected button. I also added the "all" option to reopen all names / categories. but it doesn't work on me. I add java script code like this,
// table.column(1).visible(false);
$('button').on('click', 'a', function() {
table
.columns(2)
.search($(this).text())
.draw();
});
$('button').on('click', 'a.all', function() {
table
.search('')
.columns(2)
.search('')
.draw();
});
Is there something I forgot?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
What isn't working? Please provide more details of what happens and if there are errors in the console.
There is nothing obvious from the code you provided. Please post a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
i get this error on console element on browser
test.html?m=1:4157 Uncaught ReferenceError: table is not defined
at HTMLAnchorElement.<anonymous> (test.html?m=1:4157)
at HTMLButtonElement.dispatch (jquery-3.3.1.js:5183)
at HTMLButtonElement.elemData.handle (jquery-3.3.1.js:4991)
In Head
Buttons
Table
No happen when click the button
You are referencing the variable
table
which is not within the scope of the click event function in this code snippet:Move your two click events inside the
$(document).ready(function() { .. })
function so thetable
variable is in the same scope.Kevin
Thanks worked!
May Allah Bless You