DataManager predicate

How do I use datamanager and predicate

My JS script

var predicate1 = new ej.data.Predicate('BrandName', 'contains', $("#BrandName_filterBarcell").val());
var predicate2 = new ej.data.Predicate('Code', 'contains', $("#Code_filterBarcell").val());
var predicate3 = new ej.data.Predicate('Code1', 'contains', $("#Code1_filterBarcell").val());
var predicate4 = new ej.data.Predicate('Image', 'contains', $("#Image_filterBarcell").val());
var arr = [predicate1, predicate2, predicate3, predicate4];
var predicate = new ej.data.Predicate().and(arr); //I need to combinate every predicate with and to obtain something like predicate1 && predicate2 && predicate3 && predicate4
console.log(predicate);

This does not work. How can I fix?

9 Replies

HJ Hariharan J V Syncfusion Team August 1, 2018 12:48 PM UTC

Hi Mini, 

We have checked your query and you can chain the predicates by using the and/or method by using the below way. Please refer to the below code example, Documentation link and sample link. 

[index.js] 
var predicate = new ej.data.Predicate('EmployeeID', 'equal', 3); 
var predicate1 = new ej.data.Predicate('CustomerID', 'equal','VICTE'); 
var predicate2 = new ej.data.Predicate('OrderID', 'equal', 10251); 

// complex filter criteria 
predicate = predicate.and(predicate1); 
predicate = predicate.and(predicate2);  

new ej.data.DataManager({ url: SERVICE_URI, adaptor: new ej.data.ODataV4Adaptor }) 
    .executeQuery(new ej.data.Query().where(predicate).take(8)) 
    .then((e) => { 
        (e.result).forEach((data) => { 
            table.appendChild(compiledFunction(data)[0]); 
        }); 
    }); 


Sample               : https://stackblitz.com/edit/an6cqn?embed=1&file=index.html  

Regards, 
Hariharan 



MD Mini Dev August 1, 2018 01:07 PM UTC

Hi,
I need to get predicate1 && predicate2 && predicate3 && predicate4
So I need to get a list with for elements separated by AND condition
See attachment
(Capture2 is the scope result)

Attachment: Capture_33cc61fd.zip


MD Mini Dev August 1, 2018 01:27 PM UTC

After thousands of tests I solved with the following code:
var predicate = new ej.data.Predicate('EmployeeID', 'equal', 3); 
var predicate1 = new ej.data.Predicate('CustomerID', 'equal','VICTE'); 
var predicate2 = new ej.data.Predicate('OrderID', 'equal', 10251);
var r = new ej.data.Predicate.and([predicate, predicate1, predicate2]);     
console.log(r);
[...]


HJ Hariharan J V Syncfusion Team August 2, 2018 01:05 PM UTC

Hi Mini,  
Thanks for your update. 
We are happy to hear that your problem has been resolved. 

Please get back to us if you need further assistance from us. 
Regards,
Hariharan 



MB Marko Bezjak March 29, 2019 04:31 PM UTC

Hello,

I want to filter my Gantt data with predicate according to this if statement:
if (    (item.foo == 1 || item.foo == 2 )  &&   ( item.xyz == "a" || item.xyz == "b")   )

Note how "( , )" are possitioned... now i've been trying to get it to work for 4 hours now and every single predicate i write just does this to data:
if (    item.foo == 1 || item.foo == 2    &&    item.xyz == "a" || item.xyz == "b"   )

...which is completly wrong. 
In documentation it says it is ment for addvanced filtering but i cannot get to work even for this simple example...

Please provide me with example on codePen if possible.
Thank you in advance. BR.


MB Marko Bezjak April 1, 2019 12:52 PM UTC

Well I figuered that predicates are not really the problem here. Basically what i need in GANTT is filterType = "excel". Is there any possible way to do this in gantt?


MS Mydeen S N Syncfusion Team April 2, 2019 12:45 PM UTC

  
Hi Mini, 

Currently we don’t have excel filter support for Gantt components and it will be included in any of our upcoming release. However you can use the default menu filter type. Please find the sample link  in below. 


Regards, 
Mydeen S N 



MB Marko Bezjak April 3, 2019 10:01 AM UTC

Hello,

Thank you for your reply and by the way the new Gantt looks awesome. We are using v1 gantt for quite a long time now and we are really looking forward to migrate to the new one. Keep up your good work and let us know when the new gantt is ready and better!

Br. Marko


MS Mydeen S N Syncfusion Team April 3, 2019 11:03 AM UTC

Hi Marko, 

Thanks for the update and interest in our Essential JS 2 Gantt component which is currently in preview version. We will inform you once the stable version of the Gantt component with all features are included. 

Please get back to us if you need any further assistance. 

Regards, 
Mydeen S N 


Loader.
Up arrow icon