Search for value in cell of table
Search for value in cell of table

Hello,
I have a table where I am adding rows with row.add() function,
Now I need to check in a particular column that x value exists in any of row of the table,
If the value exists, then I will add some action on that row,
and if the value does not exist, then it will add a row.
So how can we search a specific column?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Its not clear to me exactly what you want. Maybe
createdRow
orrowCallback
is what you are looking for.Kevin
@kthorngren
Hello Kevin,
See below code,
Here I need to find that row which has value and need to update that row data with the newly created row.add()
If I understand correctly you want to add the row if it doesn't exist in the table but if it does then update the existing row. Is this correct?
You can use
row().data()
to get the row data. Use therow-selector
as a function to find the row matching your criteria. See the function example in the docs.Then use
row().data()
to update the row data.Kevin
@kthorngren ,
Thank you, I could able to get row which is matching criteria with below code,
Now how can I update this specific fetched row or any of it's cell only?
The variable
matchdata
will contain an array of one or more rows, since you usedrows()
. If you just want one row then userow()
.For this example I will assume each
rowdata.item_id
is unique so you will get only one row. Try this:If you need to use
rows()
to get multiple rows then you will need to loop through the matchRow array of rows to update them individually.Kevin
Hello Kevin,
It worked, thank you,
Can you help me how can I assign data to form field input in this row?
Below linked discussion is my form field input.
https://datatables.net/forums/discussion/comment/183746
Start with the jQuery val() method. If you need help with this please start a new thread with your test case showing what you are trying to do.
Kevin