evoluteur / structured-filter

jQuery UI widget for structured queries like "Contacts where Firstname starts with A and Birthday before 1/1/2000 and State in (CA, NY, FL)"...
http://evoluteur.github.io/structured-filter/
MIT License
258 stars 61 forks source link

Custom OR logic? #5

Open vladiibine opened 9 years ago

vladiibine commented 9 years ago

It would be awesome if I could do filtering like this: { {Username contains 'asdf' AND Lastname contains 'foo'} OR {Username startswith 'A' and age < 13} }

This way a lot more flexible queries could be built

evoluteur commented 8 years ago

Yes, adding the ability to have AND or OR would make it way more flexible but it would also need parenthesis. This is a more complex UX pattern. I'm not sure which direction I want to go with this project (easier but more limited or flexible but more complex). I'll think about it.

mehkar commented 8 years ago

My solution (with php):

structured-filter.js

var evoLang={sYada:'Multi'}
//--
evoAPI={sYada:'yada'}
//--
default:
    EvoUI.inputOption(evoAPI.sYada, evoLang.sYada);

custom.php

                         if ($operator=="yada"){ 
                        $gelen_degerler=explode(",",$search_values);
                        $numItems = count($gelen_degerler);

                        $yada_i = 0;
                        $filtre_degerim=" and (";
                        foreach($gelen_degerler as $deger)
                        {
                            $filtre_degerim.=' f'.$i.'.deger like "%' . $deger.'%" ';
                            if(++$yada_i === $numItems)
                                $filtre_degerim.= ') ';
                            else
                                $filtre_degerim.= ' or ';
                        }
                        $additional_where = $filtre_degerim;
                    }
                     $sql="Select * from table where salary=1000 ".$additional_where;

Usage : Select "multi" options and type values with comma. Like "name1,name2"

andreas83 commented 8 years ago

+1 for operators between conditions.

jerodfritz commented 8 years ago

+1 for operators

ruden commented 8 years ago

:+1:

aurora commented 7 years ago

:+1:

phmulin commented 4 years ago

👍 + for operators

jasonhildebrand commented 3 years ago

I think this is a strong library as-is - without the complexity of boolean logic and parenthesis. This keeps the implementation and UX much simpler, while meeting the needs for many use cases.

See https://querybuilder.js.org/ if you need to handle more complex use cases.