How to add a hidden column to display filter values in the dropdown?
How to add a hidden column to display filter values in the dropdown?
I am using datatables from my project and it works great. However I am running into a problem with column filtering.
Position column has too long values. Using select.append( ''+d.substring(0,15)+'' ); doesn't work as I want the text to be different for each value.
Is there a way to use a hidden column with simple text to display for filtering so that I dont run into this?
So "System Architectghhghjjkjukjkj" for example would look Sys Architect in the column filter.
Link to my code - https://live.datatables.net/clone/7735/edit
Thanks.
Answers
How would you map "System Architectghhghjjkjukjkj" to "Sys Architect"? If you can programmatically do this then you can change this code:
By programmatically changing the value of
d
in+ d + '</option>
. Leave thevalue="' + d
as the original value.You could use a hidden column but you would need to change the code to loop through all the rows so you can access both the Position column and the hidden column at the same time.
Please provide more details of how the mapping will work then we can offer some suggestions. Maybe you can update the test case with an example of the actual data and what you want the select text to look like.
Kevin
If this mapping comes from the server maybe you can make a separate object returned in the data with the mapping values. You can then use that JSON data, assuming you are using
ajax
, to build the select options.Kevin
Hmm is there an example of this? I am not a developer so it would be helpful to see an example. Thanks
I provided a couple options. Which one?
It would help to understand how this mapping will work.
Kevin
I think this option is better. > By programmatically changing the value of d in + d + '</option>. Leave the value="' + d as the original value.
Here is my updated example. Thanks.
https://live.datatables.net/tesibise/1/edit
Another thing I noticed was since the column Position has html tags and special characters, the filtering crashes. My project has similar values in the table.
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Sounds like there is a difference in what this code thinks the data is:
And what this is building as the option value:
You can compare the two or update the test case to show the data you are having issues with so we can take a look.
Kevin
I figured out a better option. Using the hidden column (test case above link), I just modified the code to filter by column 6 instead of 1. It works now. Thanks for your time.
table.columns([0, 6, 2]).every(function()
Thats a simple solution!
Kevin