When I use a checkbox I want to be able to search for checked

When I use a checkbox I want to be able to search for checked

ben_daviesben_davies Posts: 1Questions: 1Answers: 0

Link to test case: https://jsfiddle.net/ben_davies/tfrh4m6e/1/
Debugger code (debug.datatables.net):
Error messages shown: None
Description of problem: So I have a search row at the top of the table and say you want to only get checked values you would type checked in the boolean column search box but nothing shows; In my implementation I have a select2 dropdown to choose from checked or unchecked but in this example if you type checked nothing shows i have tried to add a data attribute so the data contains the word checked from my assumption search looking for text matching what you have written

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited October 2020 Answer ✓

    Your checkbox looks like this:
    <input type='checkbox' data-valset='unchecked'>

    Are you expecting to search for the value in data-valset?

    You are using that.search(val).draw();. This uses smart search meaning the searching for checked will also result in displaying rows with the value unchecked

    I would look at using a type based search plugin to modify the the checkbox data to something you can search.

    I built a simple example that you can start from:
    https://jsfiddle.net/1bc30gd4/

    Assuming you are wanting to use valset I changed valset to use n for unchecked and y for checked. You can change these appropriately. Note this also affects sorting. Note this will require that you keep up with valset and change it appropriately. You might also need to use cell().invalidate() when updating valset.

    Kevin

This discussion has been closed.