Trying to create a yadcf filter for a column with images
Trying to create a yadcf filter for a column with images
I need to create a filter on a tipical columns created with images: each field is an image with this format:
<img src='http://lab.onclud.com/psm/blackcircle.png' class='notasg'>
I've created a fiddle example here.
An explication:
* there are only 2 diferents status: [assigned/not assigned] although there are 4 diferents images (black, red, yellow and green).
* Only black image correspond to not assigned status. The others three ones (red, yellow and green) correspond to assigned status.
* As you could see, I've tried to differentiate those status by class HTML tag in img elements (notasg/asgn).
Thanks in advance.
Replies
You can make use of the datatables HTML5 data-* attributes, and then tell yadcf to rely on this dt feature with the use of html5_data
So your
td
will look something like<td data-search="assigned"><img src='http://lab.onclud.com/psm/redcircle.png' class='asgn'></td>
and yadcf init will look like
var oTable = $('#example').DataTable();
Notice that I used
filter_match_mode: 'exact',
because I useddata-search="notassigned"
anddata-search="assigned"
, and since the assigned word included inside notassigned I had to tell yadcf to perform an exact search, this can be avoided if you will use unique search term in yourdata-search=
attribute,See working jsfiddle
Daniel, thanks again for your help. It works.
I have to ask you other question about this problem:
How could I filter this column pressing button [assigned] to obtain only rows with this column data-search="assigned"???
Here is the modified fiddle; as you could see, the button only throws an alert.
Thanks in advance x2
You must go over yadcf docs to uncover all of its possibilities, use
yadcf.exFilterColumn
, see working jsfiddle jsfiddle.net/m26jzxsf/1Hi again Daniel,
I'm getting data from a json, so I can't put:
<td data-search="notassigned">
directly on HTML code. As a solution, I've used createdCell (columnDefs option) as you could see on the next updated fiddle.
In this one, as you could test, your previously created filter doesn't work. I've tried some solutions, but no one has worked.
Please help me again on this one. Thanks in advance.
Found this topic interesting so took a look. I did not find a way to make it work with
data-search
either (not that I'm an expert or anything). Even tried following the example by backing out all the yadcf code. Seems ifdata-search
is rendered by DT then it doesn't work. Searching the forum I found a few others with the same result. Looks like most did some form of the second example during column render.I did the same with your example:
https://jsfiddle.net/m26jzxsf/3/
Kevin
Hi Kevin and thanks for your help,
but your example doesn't work, not???
You are right... forgot to save it. Try this one:
https://jsfiddle.net/m26jzxsf/6/
Notice the removal of
html5_data: 'data-search',
,Kevin
Kevin, thanks a lot for your solution. It works like a charm.
Hi again to all,
Im trying to use FixedHeaders extension, and continue with my old example that Kevin and Daniel helps me to solve.
The problem now is that I cant make fixedHeader extension works.
Here is my fiddle.
Please help me to merge all. Thanks in advance.
Here you go:
https://jsfiddle.net/0566dbvv/28/
Added the FixedHeader CSS and enabled fixedHeader in the DT initialization.
Kevin
Thanks again Kevin. I forgot to include CSS file.
Kevin, back to my old problem...
Will be posibble to filter in the button by asigned/not assigned and, in the column filter by the colour???
I remeber you the facts: I have four images: black, green, yellow and red. And I have two possible status: assigned/not assigned.
black image belongs to not assigned status and green, yellow and red to assigned status.
Here is my update fiddle.
Thanks in advance...Again
Changed the filter type to regex and your filter button event to this:
See updated jsfiddle. Seems to work for the button and for the select drop down.
Kevin
Thanks again Kevin. Works fine.
Hi again to all,
I reopened this post to ask for this:
Will be posible to sort this image column?
Returning to my updated fiddle, all I want is to sort this first column (Status) somehow.
Thanks in advance again.
I think you might be able to use this sorting plugin:
https://datatables.net/plug-ins/sorting/alt-string
All you should need to do is set an
alt
tag for each of your images and enable the plugin on that column.Kevin
Hi again Kevin,
Could you send me an example fiddle to see it in action???
Thanks in advance x2.
See updated jsfiddle.
I added
alt='black'
or whatever the appropriate color is to eachimg
. Added the alt-string plugin andtype: 'alt-string',
to the columnDefs.Kevin
Kevin, thanks again for your help. Its works.