StefH / KendoGridBinderEx

This is a ModelBinder designed to consume an http request and build a json serializable object for the Kendo UI Grid datasource. AutoMapper is used to support mapping from ViewModel <> Entity.
MIT License
54 stars 24 forks source link

Filters not working with dates #44

Open TDK1964 opened 4 years ago

TDK1964 commented 4 years ago

I am using the .NET Core 2 example and added a new property to the the EmployeeModel

public DateTime? HireDate { get; set; }

If I then try and filter on this column and select "is null" as the filter criteria I get this error.

System.FormatException: String '' was not recognized as a valid DateTime. at System.DateTimeParse.Parse(ReadOnlySpan1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider) at KendoGridBinder.Containers.FilterObject.GetExpression[TEntity](String field, String op, String param, String ignoreCase) at KendoGridBinder.Containers.FilterObject.GetExpression1[TEntity]() at KendoGridBinder.KendoGrid2.GetFiltering(FilterObjectWrapper filter) at KendoGridBinder.KendoGrid2.ApplyFiltering(IQueryable1 query, FilterObjectWrapper filter) at KendoGridBinder.KendoGrid2..ctor(KendoGridBaseRequest request, IQueryable1 query, Dictionary2 mappings, Func2 conversion, IEnumerable1 includes) at KendoGridBinder.KendoGrid1..ctor(KendoGridBaseRequest request, IEnumerable1 source, Dictionary2 mappings, Func2 conversion, IEnumerable1 includes) at OfficeManager.Features.Project.ProjectController.Project_Read2(KendoGridMvcRequest request) in C:\Data\Repos\TDK1964\OfficeManager\OfficeManager\Features\Project\ProjectController.cs:line 96 at lambda_method(Closure , Object , Object[] ) at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 107 at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

` var url = '@Url.Action("Grid")';

var dataSource = {
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true,
    pageSize: 10,
    transport: {
        read: {
            type: 'post',
            dataType: 'json',
            url: url
        }
    },
    schema: {
        data: 'Data',
        total: 'Total',
        model: {
            id: 'EmployeeId',
            fields: {
                FirstName: { type: 'string' },
                LastName: { type: 'string' },
                Email: { type: 'string' },
                HireDate: { type: 'date' }
            }
        }
    }
};

$('#grid').kendoGrid({
    dataSource: dataSource,
    height: 410,
    columns: [
        { field: 'FirstName', title: 'First Name' },
        { field: 'LastName', title: 'Last Name' },
        { field: 'Email', title: 'E-Mail' },
        { field: 'HireDate', title: 'Hire Date' }
    ],
    filterable: true,
    sortable: true,
    pageable: true
});`