Ho to show single value select in multi value column

Ho to show single value select in multi value column

BrettABrettA Posts: 12Questions: 4Answers: 0

Hi, I am using the multi choice select drop down filter from here:
http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html
But as per the image attached, I would rather have each individual Term placed in the Drop-down, instead of the combination of Terms.
So if Finance is selected, it shows all items with "Finance" and "Finance; Accounting" etc.
These Terms are dynamic, so can't use Static Values, we need to be able to pull the Terms from the column.

Any code changes are appreciated.

bms.PNG 16.6K

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @BrettA,

    That would be fairly easy to do. In that example, instead of creating the dropdown with the data, like here:


    column.data().unique().sort().each( function ( d, j ) { select.append( '<option value="'+d+'">'+d+'</option>' ) } );

    You would add those values you mentioned above: "Finance", "Accounting", etc.

    Then, instead of searching for $(this).val() - you would just search for the roles under each of those groupings.

    Cheers,

    Colin

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Hi Colin, thanks for responding.
    I tried changing it to: select.append( '<option value="Finance">Finance</option>' ) but it only showed items with the singular "Finance" term, not items with "Finance; Accounting"
    Is there a way to grab each term in between the semi-colon and add it to the drop-down?

  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    edited June 2018

    Hi @BrettA ,

    Here's an example here that would match what you want. You define the list of roles at the top, then those get slotted into the dropdown. Does that work?

    Cheers,

    Colin

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Hi Colin, The end result is exactly what I need but this code won't work for my setup.
    The Terms are random for each item and controlled from another list, which can change at any time from that source list. approx: 20x Terms
    My hope is somehow grab all the Terms, separate them by semi-colon display them as individual vales in the drop-down.

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi again @BrettA ,

    This might do it then - so it's taking the list, displaying as you are, then breaking it down into the individual components when selected. I put a destroy on the table, so that if you get a new list, you just reinitialise the table and it'll pick it up. Hope that's nearer to what you want.

    Cheers,

    Colin

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Hi Colin, thanks but that's what I have right now, original post image attached.
    I just tried your live link and if I put all single names like this, it works.
    var options = [
    'System Architect;',
    'Software Engineer;',
    'Javascript Developer;',
    'Software Engineer;',
    'Javascript Developer',
    'Financial Controller',
    ';Regional Director',
    'Director' ];
    Thanks for your patience with this, you have been very helpful.

This discussion has been closed.