strip html from select input and get unique value

strip html from select input and get unique value

mattB6190mattB6190 Posts: 4Questions: 2Answers: 0

Hi Guys,

hope you can help!!

I have a datatable with select inputs on some columns. For one of my columns it has a specific link generated and embedded per row and displays the text as i have stripped the html i.e <a href="www.bbc.co.uk">Director</a>.

The issue that i am having is that if more than one row had Director it would appear twice in the select input. Whereas i need Director to only appear once.

example here http://live.datatables.net/xehimatu/294/edit

Many Thanks

Matt

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    The loop generating the selects is:
    table.column(idx, {search:'applied'}).data().unique().sort().each( function ( d, j ) {

    For director you have two unique values:
    <a href="www.skysports.com">Director</a>

    and
    <a href="www.bbc.co.uk">Director</a>

    My suggestion would be to first build an array of the $('<div/>').html(d).text() values then loop through the array to build the select options.

    Kevin

  • mattB6190mattB6190 Posts: 4Questions: 2Answers: 0

    @kthorngren Thank you for your advice, sadly everytime i try to build an array it kills the select inputs. Any suggestions.

    Thanks again

This discussion has been closed.