Why doesn't in work with more than one criteria or'd

Why doesn't in work with more than one criteria or'd

Jay DeeJay Dee Posts: 2Questions: 1Answers: 0

Description of problem:
I am constructing a filter on the example page to select those in the London office under 40 and all those in the Tokyo office
I expect to see only records for London or Tokyo offices and
I expect to see London office records be for persons with age less than 40.
What I get is records for Tokyo, London, San Francisco, New York, Edinburgh, and San Francisco
And ages of Londoners of 47, 41, and 38
I am asking whether I misunderstand how to build a custom search or whether this is well and truley broken because I added it to a piece of my code and it really didn't bring back the results I was expecting.
Building the example up on the page at https://datatables.net/extensions/searchbuilder/examples/api/rebuild

Office equals London gives 12 records, only London
Age less than 40 - gives 6 records for Londoners under 40
I indent the Age condition so that it is and'ed with the London office condition AND with the new condition
I change the outer And to an Or
It changes to 31 records AND the Londoners are no longer constrained to under 40.
Getting Details gives:

{
    "criteria": [
        {
            "condition": "=",
            "data": "Office",
            "type": "string",
            "value": [
                "London"
            ]
        },
        {
            "criteria": [
                {
                    "condition": "<",
                    "data": "Age",
                    "type": "num",
                    "value": [
                        "40"
                    ]
                }
            ],
            "logic": "AND"
        },
        {
            "condition": "=",
            "data": "Office",
            "type": "string",
            "value": [
                "Tokyo"
            ]
        }
    ],
    "logic": "OR"
}

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    It looks like your logic nesting isn't quite right there. This appears to work for me:

    {
        "criteria": [
            {
                "criteria": [
                    {
                        "condition": "=",
                        "data": "Office",
                        "type": "string",
                        "value": [
                            "London"
                        ]
                    },
                    {
                        "condition": "<",
                        "data": "Age",
                        "type": "num",
                        "value": [
                            "40"
                        ]
                    }
                ],
                "logic": "AND"
            },
            {
                "condition": "=",
                "data": "Office",
                "type": "string",
                "value": [
                    "Tokyo"
                ]
            }
        ],
        "logic": "OR"
    }
    

    Allan

  • Jay DeeJay Dee Posts: 2Questions: 1Answers: 0

    Thank you so much! Seeing it I can see the logic is what I was trying for... Could not find a documentation page on this site, though there is a manual I consulted.

Sign In or Register to comment.