split the comma separated values of a column (1) Tags and make a dropdown filter with single value
split the comma separated values of a column (1) Tags and make a dropdown filter with single value
split the comma-separated values of a column (1) Tags and make a dropdown filter with a single value
like Column 1 Tags -> Row 1 have values (Tag A, Tag B, Tag C) && And Row 2 have (Tag A, Tag C, Tag D)
And dropdown filter looks alike
1st index -> Tag A, Tag B, Tag C
2nd index -> Tag A, Tag C, Tag D
instead of
1st index -> Tag A
2nd index -> Tag B
3rd Index -> Tag C
4th Index -> Tag D and So on
Here is the code I am using
...
initComplete: function () {
this.api().
columns([1]).every( function () {
var column = this;
var select = jQuery('<select id="coulumn 1"><option value=""></option></select>')
.appendTo( jQuery(column.header()).empty() )
.on( 'change', function () {
var val = jQuery.fn.dataTable.util.escapeRegex(
jQuery(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
...
Answers
I'm not sure how to specifically answer your questions without seeing a test case with your specific data. But the code the builds the select is this:
You can modify it to suit your needs. If you still need help please build a simple test case with an example of your data so we can help you with your code.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren Here is the image link
ibb.co/kDPpSYk
maybe it will help you to Understand the problem
Thanks
The best way to get help is if you build a simple test case with your data.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
here are the solution
Looks good, thanks for posting,
Colin
Hey @colin, I am a fan of your codes. I understand many things by studying your codes
I am using this for filter
I have comma separated values in 4th column. How I can use separate values as a option of dropdown filter?
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Below is the test case @colin :
http://live.datatables.net/hibidibu/1/edit?html,css,js,output
Please check the filter in 2nd and 3rd columns and comma separated values
See if this thread gets you started. See the example from the thread. For a complete solution it will probably require two loops; the first building an array of the split items making sure the array only contains unique data. The second looping through in sorted order to build the selects.
Kevin