Override Process Operator

Is it possible to extend the DataUtil class at runtime?  Looking at something in the DataUtil.OperatorSymbols function and then the subsequent mapping functions for EJ2 ECMA 5.  Specifically, I want to pass the following to the server so I can work with multiple values.  With the below, how can I get EJ2 to not throw an error for the operator being "in", i.e. how can I create custom operators that get passed straight through to the server?


chartQuery.where('items.assigned_to_id','in',dashboard_dropdowntree.value);

7 Replies

BS Balaji Sekar Syncfusion Team January 25, 2022 12:47 PM UTC

Hi Mark, 

Greetings from the Syncfusion support. 

By default, we can pass the filter query with supported operators alone but, you have using “in” operators in DataManager query so, we need to additional information about query for validating further. 


Since please share the below details to us that will help to validate further. 
  1. Share the complete DataManager code example.
  2. Ensure the purpose of using “in” operator to DataManager query.
  3. If possible to share replicating sample.

Regards, 
Balaji Sekar. 



MA Mark January 25, 2022 03:25 PM UTC

Its pretty much what I said - I need to add a new supported operator (in) which currently is not supported so how can I override the default function at runtime to support it.  Here is the code as requested:


var dashboard_piechart2_ds = new ej.data.DataManager({
url: '/api/Procurement/Dashboard/Charts/totalRequestsByCategory',
adaptor: new ej.data.UrlAdaptor(),
crossDomain: true,
});


//This is what we want to accomplish - not working
var chartQuery = new ej.data.Query().where('group_id','in',[1,2,3,4]);

pieChart1 = new ej.charts.AccumulationChart({
series: [
{
dataSource: dashboard_piechart1_ds,
query: chartQuery,
type: 'Pie',
radius: '100%',
xName: 'x',
yName: 'y',
dataLabel: {
visible: false,
position: 'Inside', name: 'text',
font: {
fontWeight: '600'
}
},
},
],
enableSmartLabels: true,
tooltip:{enable: true}
});
pieChart1.appendTo("#dashboardPieChart1");

The payload to the server would now have:

{
"requiresCounts": true,
"where": [
{
"isComplex": false,
"field": "group_id",
"operator": "in",
"value": [1,2,3,4],
"ignoreCase": false
}
]
}



We could then do a SQL parser like:

SELECT * FROM myTable WHERE group_id in (1,2,3,4);



JC Joseph Christ Nithin Issack Syncfusion Team January 26, 2022 04:45 PM UTC

Hi Mark, 

  Thanks for your update. 

  Based on your requirement, you want to pass a custom filter operator(in) in your query. Currently we are checking the feasibility of your query from our end. We will provide further details on this on or before 28th January, 2022. We appreciate your patience until then. 

Regards, 
Joseph I. 



MA Mark January 28, 2022 03:49 PM UTC

Thank you.  I will be looking forward to your response and possible solution.



PS Pavithra Subramaniyam Syncfusion Team January 31, 2022 11:10 AM UTC

Hi Mark, 
 
Thanks for your patience. 
 
We have checked the scenario of using custom operator in our DataManager library, but we found that it is not feasible. However, you can send your own filtering criteria by using the “addParams” method of EJ2 Query. 
 
 
var chartQuery = new ej.data.Query().addParams("filter", { field: "CustomerID", operator: "in", value: [123] }); 
 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Pavithra S 



MA Mark January 31, 2022 04:02 PM UTC

Thank you.  That's what we did.  It would be really nice if there was a way to just override / super the class, but I guess that's not possible with the integration / imports setup the way they currently are.  The reason why this would be beneficial, is we have a class on the server that processes the "where" block payload from EJ components, so we would just need to add the "in" processor and it would work across all products without requiring a separate addParams and then a watcher on server side, but it is what it is for now.


Thank you again for confirming!



PS Pavithra Subramaniyam Syncfusion Team February 1, 2022 10:32 AM UTC

Hi Mark, 
 
You can change the where predicate value as per your requirement by override the “processQuery” method of UrlAdaptor using the “Custom Adaptor” feature. Please refer to the below code example and documentation link for more information. 
 
        class CustomAdaptor extends ej.data.UrlAdaptor { 
            processQuery(dm, query, hierarchyFilters) { 
                // calling base class processQuery function 
                var original = super.processQuery.apply(this, arguments); 
                var data = JSON.parse(original.data); 
                // change the where value here 
                data.where = [{ 
                        "isComplex": false, 
                        "field": "group_id", 
                        "operator": "in", 
                        "value": [1, 2, 3, 4], 
                        "ignoreCase": false 
                    } 
                ] 
                original.data = JSON.stringify(data) 
                return original; 
            } 
        } 
        var dashboard_piechart2_ds = new ej.data.DataManager({ 
            url: "/Home/UrlDatasource", 
            adaptor: new CustomAdaptor() 
        }); 
  
 
 
Please get back to us if you need further assistance on this. 
 
Regards, 
Pavithra S 


Loader.
Up arrow icon