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);
}
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);
}
|
Thanks for the response
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
[HomeController.cs]
public class BigData
{
public DateTime? OrderDate { get; set; }
----
}
|
Thanks for your response
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