Filter by Date - Arguments do not match exception

Hi, I have a grid that is using remote url for the data and two of my columns that I am retrieving are date columns that have are nullable. When I go and try to apply the filter my back end throws an exception 


2021-11-17 15:33:52.261 -05:00 [Error] An unhandled exception has occurred while executing the request.
System.ArgumentException: Argument types do not match

This only happens with dates, I did a little test and flipped my dates to strings and I was able to get the filters to work (not how I wanted, but I wanted to see for myself that strings did work). Any ideas as to why I am getting that Argument types do not match? I feel like somewhere when  apply the filter, it sends probably a string and then my datasource is looking for a DateTime


<ejs-grid id="organization-resource-management" frozenColumns="1" allowFiltering="true" allowExcelExport="true" toolbarClick="toolbarClick" width="100%" allowPaging="true" toolbar="@(new List<string>() { "Edit", "Cancel", "Update", "ExcelExport" })" cellEdit="cellEdit">

<e-data-manager url="@Url.Action("List", "ResourceManagement", new { area="Organization" })" adaptor="UrlAdaptor" batchUrl="@Url.Action("UpdateResources", "ResourceManagement", new { area="Organization" })"></e-data-manager>

<e-grid-filtersettings type="Menu"></e-grid-filtersettings>

<e-grid-editSettings allowEditing="true" mode="Batch"></e-grid-editSettings>

        <e-grid-columns>

<e-grid-column field="Name" allowEditing="false" allowSorting="false" type='string' headerText="Study" width="140"></e-grid-column>

<e-grid-column field="StageDetail.Name" allowEditing="false" filter="@(new { type="CheckBox", itemTemplate = "#template-stage-filter"})" headerText ="Stage" template="#template-stage" width="120"></e-grid-column>>

<e-grid-column field="App.Name" allowEditing="false" filter=@(new { @operator="contains"}) headerText="Application" type='string' template="#template-application" width="200"></e-grid-column>

<e-grid-column field="Manager.AccountId" filter=@(new { @operator="contains"}) foreignKeyField="AccountId" foreignKeyValue="Name" editType="dropdownedit" type='string' allowSorting="false" edit="new {@params = businessAnalystDropDownList }" headerText="Mananger" width="200" dataSource="Model.Managers"></e-grid-column>

<e-grid-column field="PrimarySupport.Id" filter=@(new { @operator="contains"}) foreignKeyField="Id" foreignKeyValue="Name" editType="dropdownedit" type='string' allowSorting="false" edit="new {@params = supportTeam }" headerText="Primary Support" width="225" dataSource="Model.SupportTeams"></e-grid-column>

<e-grid-column field="SecondarySupport.Id" filter=@(new { @operator="contains"}) foreignKeyField="Id" foreignKeyValue="Name" editType="dropdownedit" type='string' allowSorting="false" edit="new {@params = supportTeam }" headerText="Secondary Support" width="225" dataSource="Model.SupportTeam"></e-grid-column>

<e-grid-column field="SeniorSupport.Id" filter=@(new { @operator="contains"}) foreignKeyField="ApplicationSupportTeamMemberId" foreignKeyValue="Name" editType="dropdownedit" type='string' allowSorting="false" edit="new {@params = supportTeam }" headerText="Senior Support" width="225" dataSource="Model.SupportTeam"></e-grid-column>

<e-grid-column field="Sponsor" allowEditing="false" allowSorting="false" filter=@(new { @operator="contains"}) type='string' headerText="Sponsor" width="140"></e-grid-column>

<e-grid-column field="TargetDate" allowEditing="false" allowSorting="false" headerText="Target" width="150" customFormat="@(new {type = "datetime", format = "yyyy-MM-dd hh:mm a" })"></e-grid-column>

<e-grid-column field="ActualDate" allowEditing="false" allowSorting="false" headerText="Actual" width="150" customFormat="@(new {type = "datetime", format = "yyyy-MM-dd hh:mm a" })"></e-grid-column>

        </e-grid-columns>

</ejs-grid>


public async Task<IActionResult> List([FromBody]DataManagerRequest dm)

        {

            var dataSource = getData();

            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

            {

//fails here

                dataSource = operation.PerformFiltering(dataSource, dm.Where, dm.Where[0].Operator);

            }

            int count = dataSource.Count();

            if (dm.Skip != 0)

            {

                dataSource = operation.PerformSkip(dataSource, dm.Skip); //Paging

            }

            if (dm.Take != 0)

            {

                dataSource = operation.PerformTake(dataSource, dm.Take);

            }

            return dm.RequiresCounts ? Json(new { result = dataSource, count = count }) : Json(dataSource);


        }


6 Replies

RS Rajapandiyan Settu Syncfusion Team November 18, 2021 01:53 PM UTC

Hi Jorge,  

Thanks for contacting Syncfusion support. 

We are tried to reproduce the reported behavior with the provided code example, but it was unsuccessful at our end. Filtering on Date column is working fine in the URL Adaptor with the latest version. Kindly share the below details to replicate it at our end. 

  1. Share the Grid script version and .NET Core version
  2. Share the screenshot of Network Tab details and the dm.where value in the server side.
  3. If possible, share the issue reproducible sample.
  4. Also, use IEnumerable type of datasource to filter the list.

 
public ActionResult UrlDatasource(DataManagerRequest dm) 
        { 
            IEnumerable<OrdersDetails> DataSource = OrdersDetails.GetAllRecords().ToList(); 
            DataOperations operation = new DataOperations(); 
            --- 
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            ---- 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
        } 


Regards,  
Rajapandiyan S 



JO Jorge Orellana November 19, 2021 03:11 AM UTC

Thanks for the response


  1. net core 5.0 using Syncfusion.EJ2.AspNet.Core 19.3.0.53
  2.  here is the request payload on the server side:
I think its in the Value = ValueKind = string "Date"

As a test on my own, I created

var where = new List

{

new WhereFilter

{

Condition = "and",

Field = null,

IgnoreCase = false,

IsComplex = true,

Operator = null,

predicates = new List()

{

new WhereFilter

{

Condition = "and",

Field = null,

IgnoreCase = false,

IsComplex = true,

Operator = null,

predicates = new List()

{

new WhereFilter

{

Condition = null,

Field = "FPFVDetail.TargetDate",

IgnoreCase = false,

IsComplex = false,

Operator = "greaterthan",

predicates = null,

value = DateTime.MinValue

}

}

},

new WhereFilter

{

Condition = "and",

Field = null,

IgnoreCase = false,

IsComplex = true,

Operator = null,

predicates = new List()

{

new WhereFilter

{

Condition = null,

Field = "FPFVDetail.TargetDate",

IgnoreCase = false,

IsComplex = false,

Operator = "lessthan",

predicates = null,

value = DateTime.MaxValue

}

}

}


}

}

};


and plugged that into

dataSource = operation.PerformFiltering(dataSource, where, dm.Where[0].Operator);


and did not observe any exceptions and the grid filtered properly



RS Rajapandiyan Settu Syncfusion Team November 22, 2021 12:30 PM UTC

Hi Jorge,  

Thanks for your update. 
 
We have analyzed your query at our end. Kindly share the type of the date field in your dataSource. Because, to perform the Grid actions like Filtering, Sorting, etc., on date column, it should be in date format. 
 
Find the below screenshot and code example for your reference. 
 
 
[HomeController.cs] 
 
public class BigData 
        { 
             
            public DateTime? OrderDate { get; set; } 
            ---- 
        } 
 
 
Screenshot #1: Response send the server 
 
 
Screenshot #2: Retrieve the response at server 
 
 
By default the dateObject will be set to the server. But in your screenshot string value will be get at server. so, share which type of field you have used on date column? 
 
You can use your workaround, if it resolves your problem. 
 
Find the below sample for your reference. 
 
 
Still, if you face the issue, kindly share the below details to validate further. 
 
  1. Which type of field (DateObject/string) you have used for date column? Share the Class details.
  2. Share the issue reproducible sample or make the issue in the given sample.
 
Regards,  
Rajapandiyan S 



JO Jorge Orellana November 22, 2021 06:16 PM UTC

Thanks for your response


  1. I am using a nullable date time field 

2. I will try to provide code that reproduces the error 


JO Jorge Orellana November 22, 2021 07:41 PM UTC

Ok after a long fight with this I have found something.


my startup CS was using




because we are not wanting to use Newtonsott.Json library but this is what was causing me grief.


As soon as installed the Newtonsoft package and flip it over to


my dates started to show the way in which your demo showed. 


I guess the new question becomes, do I have to use NewtonsoftJson? can what I had originally used in my project and if so, what would be the right configuration so that I can get it to work.


Thank you 



RS Rajapandiyan Settu Syncfusion Team November 23, 2021 11:37 AM UTC

Hi Jorge,  

Thanks for your update. 

We need to install NewtonSoft.JSON as dependency since Syncfusion.EJ2.AspNet.Core dependent to NewtonSoft.JSON package. It is explained in the below documentation. 


Screenshot: 
 

So, we suggest you to use NewtonSoftJson (Microsoft.AspNetCore.Mvc.NewtonsoftJson) dependency in your project. Please let us know if you have any concerns. 

Regards,  
Rajapandiyan S 


Loader.
Up arrow icon