0
votes

I am developing an application using ASP .NET MVC 4 which will use Kendo grid to populate the result as summary. I am using Server side operations ( paging,filtering and sorting). I used to generate the grid via script rather than using the MVC wrapper provided by kendo UI.

I have a scenario in which the user will give the filters from the query string itself. Sample URL is like below

http://localhost/Summary/Audit?Startime=19/02/1013&Endtime=12/01/2013&Name=User1

I am able to fetch and sort out the query string and also stored in a memory location. I need to pass those values as filter collection (as default to the controller) while creating the grid itself. Is there any way to achieve the above scenario? And also, I need those values to be filled at the filter boxes (Filter form) when the user choose any filter field. Thanks.

Below is the way i am using to create the grid via script

`var grid = $("#gridSummary").kendoGrid({
    dataSource: {
        type: "aspnetmvc-ajax",
        dataType: "json",
        transport: {
            read: "/Summary/GetAudit",
            parameterMap: function (data, type) {
                if (type == "read") {
                    if (data.filter) {
                        if (data.filter.filters) {
                            var FilterCol = "";
                            var coldelmtr = "<::>";
                            var rowdelmtr = "{::}";
                            for (var i = 0; i < data.filter.filters.length; i++) {
                                if (FilterCol.length > 0)
                                    FilterCol += rowdelmtr;
                                FilterCol += data.filter.filters[i].field + coldelmtr + data.filter.filters[i].value;
                            }
                        }
                    }
                    return {
                        page: data.page,
                        pagesize: data.pageSize,
                        filters: FilterCol
                    }
                }
            }
        },
        pageSize: 50,
        schema: { data: "Data", total: "Total",
            model: {
                fields: {
                    DateTime: { type: "date" },
                    Name: { type: "string" },
                    Action: { type: "string" },
                    On: { type: "string" },
                    Type: { type: "string" },
                    By: { type: "string" }
                }
            }
        },
        serverPaging: true,
        serverFiltering: true,
        serverSorting: false,
        serverAggregates: true
    },
    scrollable: {
        virtual: true
    },
    sortable: true,
    resizable: true,
    filterable: true,
    filterMenuInit: function (e) {
        if (e.field === "DateTime") {
            var firstValueDropDown = e.container.find("select[data-role='dropdownlist']:eq(0)").data("kendoDropDownList");
            //                firstValueDropDown.readonly();
            firstValueDropDown.wrapper.hide();

            var secondValueDropDown = e.container.find("select[data-role='dropdownlist']:eq(1)").data("kendoDropDownList");
            //secondValueDropDown.readonly();
            secondValueDropDown.wrapper.hide();

            var thirdValueDropDown = e.container.find("select[data-role='dropdownlist']:eq(2)").data("kendoDropDownList");
            thirdValueDropDown.select(1);
            //thirdValueDropDown.readonly();
            thirdValueDropDown.wrapper.hide();
        }
    },
    columns: columnsCollec
});`
1

1 Answers

1
votes

You can take a look at this sample project which shows how to implement server-side paging, sorting and filtering using ASP.NET MVC and Kendo UI (without the ASP.NET MVC wrappers): https://github.com/telerik/kendo-examples-asp-net-mvc/tree/master/grid-crud