1
votes

I'm using A Kendo Grid, With Server Side Filtering and Server Side Sorting. In my Data Source Transport Read method the field is always null. Any Suggestions?

This my code for initializing the Grid:

var gridDataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("Read", "GridModule")',
                    type: 'POST',
                    contentType: 'application/json'
                },
                parameterMap: function (options) {
                    options.assignmentFilters = assignmentFilters;
                    return JSON.stringify(options);
                }
            },
            pageSize: 20,
            serverPaging: true,
            serverSorting: true,
            serverFiltering: true,
            schema: {
                model: {
                    fields: {
                        LastSurveyDate: { type: "date" },
                        LastNoteDate: { type: "date" }
                    }
                },
                data: "data",
                total: "totalRows"
            }
        });

        var $grid = $('#gridAssignments');

        if (e.firstLoad) {
            $grid.kendoGrid({
                scrollable: true,

                pageable: {
                    refresh: true,
                    pageSizes: [20, 50, 100, 500, 1000],
                    buttonCount: 12,
                    messages: {
                        display: "Showing {0}-{1} from {2} Provider Contacts",
                        empty: "No Contacts Match the Filter Criteria",
                        itemsPerPage: "Contacts per page"
                    }
                },
                reorderable: true,
                navigatable: true,
                change: gridOnChange,
                dataBound: gridOnDataBound,
                dataSource: gridDataSource,
                columnReorder: gridColumnReorder, 
                columnHide: gridColumnHide,
                columnResize: gridColumnResize,
                columnShow: gridColumnShow,
                columnMenu: {
                    sortable: false,
                    messages: {
                        columns: "Choose columns",
                        filter: "Filter",
                       }
                },
                resizable: true,
                height: '720px',
                filterable: {
                    extra: false,
                    operators: {
                        string: {
                            contains: "Contains",
                        },
                        date: {
                            lt: "Is before", 
                            gt: "Is after",
                            equal: "On"
                        }
                    }
                },
                selectable: "row",
                sortable: {
                    mode: "single",
                    allowUnsort: true
                },
                columns: [ @Html.Raw(Model.GridColumns.Columns) ]
        });
        } else {
            $grid.data('kendoGrid').setDataSource(gridDataSource);
        }
1
Do you mean the Read method of GridModule is always getting null from client side? If I'm not mistaken you must also pass in the type to the parameter map function delegate like so: parameterMap: function(options, type) {}. Perhaps it's not hitting your function since you missing the arg.ramsey_tm
Yes you are correct. In my read method.Rodney

1 Answers

3
votes

For anyone that runs into the same problem...

In my case my code worked fine until I added two fields to the Schema.Model.Fields. Then for some reason the Field in my read method of my Grid Module was NULL. By default it all fields were treated as strings but when I added the two new properties then No default was used.

I had to add all my Grid's fields

            schema: {
                model: {
                    fields: {
                        LastSurveyDate: { type: "date" },
                        LastNoteDate: { type: "date" },
                        FirstName: { type: "string" },
                        LastName: { type: "string" },
                        HasNewEval: { },
                        HasCommitmentsToGet: { },
                        OnPriorityList: { type: "string" },
                        HasProductsBelowMinimum: { type: "HasProductsBelowMinimum" },
                        Points: {},
                        Title: { type: "string" },
                        Provider: { type: "string" },
                        Phone: { type: "string" },
                        TimeZone: { type: "string" },
                        Touches: { type: "string" },
                        LastNoteText: { type: "string" },
                        VerbalAging: { type: "string" }
                    }
                },

That worked for me.