showing individual terms in Searchbuilder from an array

showing individual terms in Searchbuilder from an array

honeynutzhoneynutz Posts: 2Questions: 1Answers: 0

Currently while using searchbuilder when i reference the array "cats" in searchbuilder I end up getting a dropdown with "cat2, cat3" ; "cat2, cat4" ; "cat1" -- I would like to just get a list of unique elements (eg "cat1"; "cat2"; "cat3"; "cat4"). Since the data is pulling live from AJAX, my assumption is that i need to build a variable that contains the array elements first and then do some sort of initcomplete call within the SB code... I am a bit of a novice so please excuse my lack of knowledge here.

JS Code:

 $('#example').DataTable( { 
    "ajax": "https://site.com/datastuff.json",
    "columns": [
        { "data": "system" },
        { "data": "table" },
        { "data": "name" },
        { "data": "cats",
          render: {
            _: '[, ]',
            sb:'[]'
          },
          searchBuilder: {
            orthogonal:'sb'
          },
          type: 'array'}
    ],
    dom: 'Qlfrtip'
} );

JSON (currently pulled through an AJAX request):

{
    "data":[
{
    "system": "SUSTEM1",
    "table": "TABLE1",
    "name": "FIELD1",
    "uid": "1180",
    "text": "",
    "value": 1,
    "cats": ["cat2", "cat3"]
}, {
    "system": "SYSTEM2",
    "table": "TABLE1",
    "name": "FIELD2,
    "uid": "1181",
    "text": "",
    "value": 1,
    "cats": ["cat2", "cat4"]
}, {
    "system": "SYSTEM2",
    "table": "TABLE2",
    "name": "FIELD3",
    "uid": "1182",
    "text": "",
    "value": 1,
    "cats": ["cat1"]
}
}]
}

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @honeynutz ,

    This example shows how SearchBuilder works with arrays. The Contains condition does what you are describing, if I understood correctly.

    If you are seeing behaviour that is different to that can you please provide a test case. 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.

    Thanks,
    Sandy

  • honeynutzhoneynutz Posts: 2Questions: 1Answers: 0
    edited March 2021

    @Sandy okay dumb question then -- I was trying to utilize Equals instead of Contains. Now that you said that this makes sense -- appreciate the help and thank you for the clarity

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @honeynutz ,

    No worries - happy to help :)

    Thanks,
    Sandy

This discussion has been closed.