showing individual terms in Searchbuilder from an array
showing individual terms in Searchbuilder from an array
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
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
@Sandy okay dumb question then -- I was trying to utilize
Equals
instead ofContains
. Now that you said that this makes sense -- appreciate the help and thank you for the clarityHi @honeynutz ,
No worries - happy to help
Thanks,
Sandy