[ResourcesDataSource] Differentiate between Grid-Filter and Excel-Filter Autocomplete

Hi,


In the Controller, I am doing some custom code in the ResourcesDataSource. This code needs to be executed when the Grid is filtered.

But the Excel-Like menu from the grid, guess what, also calls this ResourcesDataSource (to get values for its column to be displayed to the user). - Problem is, this time, I don't want to execute that custom code.

I can't find any means to differentiate between these two. Found on the internet that dm.RequiresCounts is my saviour, but both times it comes as "true"

I am using an URL Data Adaptor.

1 Reply 1 reply marked as answer

AG Ajith Govarthan Syncfusion Team June 23, 2020 02:55 PM UTC

Hi Catalin, 

Thanks for contacting Syncfusion support. 

By default in EJ2 Grid when we bind remote data with excel filter three request will be sent to the server-side.  

The first request will be sent when you click on the filter icon and the second request will be sent when you use autoComplete with custom filter & the third request will be sent when we filter the data. So, if you want to use the custom code when you apply filter we suggest you to check the condition with RequiresCount and Where operator.  

We have attached the code example so please refer the code for your reference. 

Code example: 
HomeController.cs 

public IActionResult UrlDatasource([FromBody]DataManagerRequest dm) 
        { 
            IEnumerable DataSource = order; 
            DataOperations operation = new DataOperations(); 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                DataSource = operation.PerformSearching(DataSource, dm.Search);  //Search 
            } 
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            { 
                DataSource = operation.PerformSorting(DataSource, dm.Sorted); 
            } 
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            int count = DataSource.Cast<Orders>().Count(); 
            if (dm.Skip != 0) 
            { 
                DataSource = operation.PerformSkip(DataSource, dm.Skip);   //Paging 
            } 
            if(dm.RequiresCounts && dm.Where != null && dm.Where.Count > 0) 
            { 
              // you can use your code here 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = operation.PerformTake(DataSource, dm.Take); 
            } 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
        } 
 


Please get back to us if you need further assistance. 

Regards, 
Ajith G. 




Marked as answer
Loader.
Up arrow icon