Search plugin - Get value of input field inside data cell

Search plugin - Get value of input field inside data cell

Cfal16Cfal16 Posts: 2Questions: 1Answers: 0

Hello. I'm trying to create a search plugin that will allow me to hide rows where the cells contain a checked off input field, however, I'm struggling to access the value of said input field. Due to unchecked input fields not being submitted in a form I've had to create a hidden input field in the same cell.

I've created a minimal implementation of my table at http://live.datatables.net/vemahaki/6/edit?html,js,output

What I'd like to do on line 29 would be something like (I'm aware this wouldn't compile):

if (checked && data[1].input.value == 0) { return false }

Anybody that has a suggestion as how I could do that? Or a completely different approach than mine.
On my actual side I have multiple tables where I'd like to do this filtering so I'd prefer not using IDs on the elements due to various reasons.

This question has an accepted answers - jump to answer

Answers

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

    There are a a couple ways you can approach this. One is to get the checked state of the actual input or the other is to keep up with the checkboxes in the rows and update either the value or the row data.

    I updated your example to show how to get the checked state of the input.
    http://live.datatables.net/vemahaki/7/edit

    It does two things. First it gets an instance of the table API from the settings parameter so you don't need the table ID. Next it uses the dataIndex parameter to get the row index and uses row().node() to get the HTML node. It uses the row node to find the checkbox and ultimately the checked state.

    I created this example previously which also shows how to keep the data value for the checkbox and use the search plugin to test for the value. This is good if you want to store the checkbox state in a DB, for example.
    http://live.datatables.net/cefadoze/3/edit

    Kevin

  • Cfal16Cfal16 Posts: 2Questions: 1Answers: 0

    Thank you very much Kevin. I suspected that the row.node was the answer. I tried with the dataindex intially where it would work as long as the initial ordering of the rows wasn't changed, which wouldn't work that well in practice :p

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Not sure if you are saying the example solution doesn't work with rowReorder. I updated it and it does seem to work with rowReorder:
    http://live.datatables.net/vemahaki/9/edit

    Kevin

This discussion has been closed.