How to search for Div innerHTML
How to search for Div innerHTML

I know it is frequently asked question in this forum, but I do not found a helping answer in that case.
I have a DataTable. The value of my last Column could have 3 states. The states are unknown
, success
and fail
. There for I create a select
box to filter for that states. The HTML Tags of the state looks like:
<td><div class="parse_fail">fail</div></td>
With that column I have two issues:
1. the sorting arrows have no function
2. the state select
search find no values
it is obviously because of the html div tag.
What I try:
1. I try custom column renderer but I understand it is for the view, not for the search and sorting.
2. I try to specify my column with
columnDefs: [
{ "type": "html", "targets": 5 }
]
but doesn't help.
3. I try to regex search for the whole div tag <td><div class="parse_fail">fail</div></td>
, but I think it is not how it works.
So how could I solve the sorting/searching problem?
This question has an accepted answers - jump to answer
Answers
Please provide a link to your page or a running test case so we can see what your code is doing. This will allow us to help diagnose the problem.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hello Kevin, thanks for your response. I try to rebuild my case in this minimal example and I found out that I can't reproduce the issue. This DataTable have no issue with the Div Tag inside the first column. So I have to find out, where the differences are. I will try to but this minimal example into my application.
@kthorngren I was now able to create a minimal example which should reproduce the issue:
2. the state
select
search find no valuesI have no idea what is different to the first minimal example. Hope this make it clear.
You have
table.column(0).search()
which is searching the first column. You want to search the second and need to usetable.column(1).search()
instead. Updated example:http://live.datatables.net/jakefuca/2/edit
Kevin
@kthorngren I am so sorry, I make a mistake and you was correct. I understand now that my first minimal examples was not representative for the problem. So I create a new minimal example and I am now really sure, that this should point to the issue.
Here in words:
- I have table where the value change on runtime.
- the last column 'State' starts with the value 'unknown'
- after about 5 min all values inside the column will have his final state ('fail' or 'success')
- I simulate this process in the example with the click button
- after the table value change by a click, the search algorithm is not able to find the new value
It takes I while to understand the problem. Do you have any idea how could I solve this?
If you haven't got many rows, the easiest way would be to call
rows().invalidate()
to rescan the table - http://live.datatables.net/jakefuca/4/editIf you do have a lot of rows, you could invalidate the specific cell that you changed with
cell().invalidate()
,Colin