This is a migrated thread and some comments may be shown as answers.

Date filter on field bound to string property

1 Answer 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd
Top achievements
Rank 1
Todd asked on 23 Aug 2013, 05:31 PM
I know that something similar was posted and that this may not be supported currently but just want to make sure I've exhausted all options within the Grid API.

I've persisted a scheduled DateTime in UTC. Due to issues with clients in various time zones I'm doing the conversion from UTC on the server (ASP.NET MVC) and casting this value to a string. I would like to re-cast this back to a DateTime instance so that I can make use of the Date filter operators in the appropriate column.
Even if I use Template() the bound property was originally a string and the filter exposes string comparison operators, which I can understand. If I try setting this using Model.Field() the result is the same. Is there a way to override this before the filter renders? Do I need to attach to a DataSource event?

My code:
(Model.ScheduledDelivery is the field in question. We want to allow the user to set a date range for filtering)
    @(Html.Kendo().Grid<ScheduledEmailSender.Web.Models.ViewModels.SubmissionViewModel>()
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(x => x.SubmissionId).Hidden();
            columns.Command(command => command.Edit().Text("Edit"));
            columns.Command(command => command.Destroy().Text("Delete")).Width(100);
            columns.Template(@<text>@GetSummary(item)</text>).ClientTemplate("<div class='email-summary'>#= EmailSubject #</div>").Title("Message Info");
            columns.Bound(x => x.ScheduledDelivery).Template(a => a.ScheduledDelivery.AsDateTime())
                .Filterable(f => f.Operators(o => o.ForDate(d => d.IsGreaterThanOrEqualTo("Is After").IsEqualTo("Equal To")
                    .IsLessThanOrEqualTo("Is Before"))));
            columns.Bound(x => x.EmailTo).Width(100).Filterable(f => f.Operators(o => o.ForString(s => s.Clear().Contains("Contains"))));

        })
        .DataSource(dataSource => dataSource
            .Ajax()
                            .Model(model => { 
                                model.Id(p => p.SubmissionId);
                            })
            .Read(read => read.Action("Submissions_AjaxRead", "Home"))
            .Destroy(update => update.Action("Submissions_AjaxDelete", "Home"))
            .Update(update => update.Action("Submissions_AjaxUpdate", "Home"))
            .PageSize(10)
            .Events(e => {
                e.Sync("refreshGrid");
            })

        )
        .Events(e =>
            {
                
                e.DataBound("Grid_dataBound").Remove("Grid_itemRemoved");

            })
        .Pageable()
        .Filterable()
        .Editable(edit => edit.Mode(GridEditMode.PopUp).TemplateName("MailEditor"))
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .Sortable()

    ) 

1 Answer, 1 is accepted

Sort by
0
Accepted
Todd
Top achievements
Rank 1
answered on 23 Aug 2013, 08:19 PM
Disregard. I'm going to allow filtering on a column that will display the UTC date and just display the string value of the converted time + the user time zone in another.Thanks.
Tags
Grid
Asked by
Todd
Top achievements
Rank 1
Answers by
Todd
Top achievements
Rank 1
Share this question
or