Can't clear search filter

Can't clear search filter

n00bmast4rn00bmast4r Posts: 3Questions: 1Answers: 0

table.column(2).search('').draw() returns empty table instead of a table with cleared filter
table.column(2).search(rarity).draw(); This is what runs before the empty table clear

How do you clear a search filter

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    It certainly should, and it appears to work okay in this example.

    Can you link to a test case showing the problem please (per the forum rules).

    Allan

  • n00bmast4rn00bmast4r Posts: 3Questions: 1Answers: 0

    Sorry, I was in a rush and was pretty mad about why it wouldn't work. I've read the rules and guidelines and I believe this should be sufficient. Thank you for your immense patience

    I was going to try and replicate the problem on a small scale application, but gave up due to time. Though this is my Github Repo right now. Please ignore the poor code as it is currently my first project. Most of the buttons don't do anything, and only the "Fetch All Talents" and "Rarity" "Any Common Rare Advanced" does anything at all

    You can visit the hosted website that's on github here. When you press "Fetch All Talents", then try to sort by Rarity (Common, Rare, etc.), It works using dataTable.column(2).search(stringOfRarity).draw();. But when I try to "clear" the filter/search with dataTable.column(2).search('').draw();, it returns "No matching records found" on the datatable.

    You can see my initialization code in table.js, or here:
    const tableConfig = { layout: { topStart: null, topEnd: null, bottomStart: 'info', bottomEnd: null, }, paging: false, lengthChange: true, order: [ [3, 'asc'], [0, 'asc'] ], columns: [ { searchable: true, orderable: true }, { searchable: true, orderable: false }, { searchable: true, orderable: false }, { searchable: true, orderable: true }, { searchable: true, orderable: false }, { searchable: true, orderable: false }, { searchable: true, orderable: false }, { searchable: false, orderable: false } ], initComplete: function () { console.log('DataTable initialized!'); } };

    const dataTable = $('#result-table').DataTable(tableConfig);

    Currently, I am making an HTML table manually, then initializing it with datatable.js with these configurations, and then adding the event listener to the table so that search features can function, if that's helpful.

    Though that is the repo, this is what I've made on JSfiddle

  • n00bmast4rn00bmast4r Posts: 3Questions: 1Answers: 0

    And while writing this I've realized that I did not put an "else" block right after the "if", which caused the problem. Sorry for wasting your time

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    It is easy done and we've all been there. Good to hear you got it working :)

    Allan

Sign In or Register to comment.