This is a migrated thread and some comments may be shown as answers.
Remote Filtering Date Bug?
5 Answers 108 Views
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 07 Jan 2012, 04:34 PM
I believe there is a bug in remote filtering dates.  The value doesn't appear to show up anywhere in the querystring.  Here is my grid:

<div id="grid"></div>
 
<script type="text/javascript">
 
    var dateRegExp = /^\/Date\((.*?)\)\/$/;
 
    function toDate(value) {
        var date = dateRegExp.exec(value);
        return new Date(parseInt(date[1]));
    }
 
    $(document).ready(function() {
        var url = '@Url.Action("Grid")';
 
        var dataSource = new kendo.data.DataSource({
            serverPaging: true,
            serverSorting: true,
            serverFiltering: true,
            pageSize: 200,
            transport: {
                read: {
                    type: 'post',
                    dataType: 'json',
                    url: url
                }
            },
            schema: {
                data: 'data',
                total: 'total',
                model: {
                    id: 'EmployeeId',
                    fields: {
                        Name: { type: 'string' },
                        Email: { type: 'string' },
                        EmployeeNumber: { type: 'number' },
                        HireDate: { type: 'date' },
                        Active: { type: 'boolean' }
                    }
                }
            }
        });
 
        $('#grid').kendoGrid({
            dataSource: dataSource,
            height: 400,
            columns: [
            { field: 'Name', title: 'Name' },
            { field: 'Email' },
            { field: 'EmployeeNumber', title: 'Emplyee #' },
            { field: 'HireDate', title: 'Hire Date', template: '#= kendo.toString(toDate(HireDate), "MM/dd/yyyy")#' },
            { field: 'Active' }
        ],
            filterable: true,
            sortable: {
                mode: 'multiple'
            },
            scrollable: {
                virtual: true
            }
        });
    });
     
 
</script>

and attached is a picture of the request in fiddler.  The operator, field, and logic show up.  Where is the value at?

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Jan 2012, 09:38 AM
Hi,

 The DataSource is using jQuery to make any requests to the remote service. It seems that jQuery by default skips any parameters which are of Date type. You should use the parameterMap setting of the DataSource to convert all dates to some string representation which jQuery can submit:

transport: {
                read: {
                    type: 'post',
                    dataType: 'json',
                    url: url
                },
                parameterMap: function(options) {
                    if (options.filter) {
                       options.filter.filters[0].value = 
kendo.toString(options.filter.filters[0].value 
, "MM/dd/yyyy") 

                    }
                    return options;
                }
            },

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Roel
Top achievements
Rank 1
answered on 17 Jul 2013, 02:46 PM
Hi Atanas,

Is this still an issue? How would you do it for all date type columns?

Thanks
Roel
0
Atanas Korchev
Telerik team
answered on 18 Jul 2013, 07:28 AM
Hello Roel,

 As far as I know jQuery still doesn't convert JavaScript dates when sending them via $.ajax. My workaround is the suggestion solution.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carles
Top achievements
Rank 1
answered on 22 Jan 2014, 06:05 PM
Any news on this ?

I have tried the workaround, the parameterMap function gets called but the grid won't return filtered results as expected.

0
Atanas Korchev
Telerik team
answered on 23 Jan 2014, 08:09 AM
Hi Charles,

jQuery still doesn't convert JavaScript dates when sending them via $.ajax. My workaround remains the recommended solution.

If you are having trouble implementing it you may consider opening a support ticket and sending us a runnable version of your project which we can troubleshoot.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Roel
Top achievements
Rank 1
Carles
Top achievements
Rank 1
Share this question
or