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

Grid In MVC4 Paging Sorting Filtering Example

0 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anilesh
Top achievements
Rank 1
Anilesh asked on 02 May 2012, 07:13 PM
Hi,

I am looking to a MCV example for kendo Grid where I can have Paging Sorting and Filtering on server side.
I have implemented the filtering option on server side in my code Here is my Code

/// On Server 
public class GridCommand
    {
        public FilterExpression Filter { get; set; }       
    }


    public class FilterExpression
    {
        public string Logic { get; set; }
        public IEnumerable<GridFilter> Filters { get; set; }
    }


    public class GridFilter
    {
        public string Operator { get; set; }
        public string Field { get; set; }
        public string Value { get; set; }
    }

public ActionResult GetContracts(GridCommand command)
        {
//Some Code
            return Json(list, JsonRequestBehavior.AllowGet);            
        }


////On Client
$("#grid").kendoGrid({
                        dataSource: {
                            type: "jsonp",
                            transport: {
                                read: {
                                    url: "/Test/GetContracts"
                                },
                                parameterMap: function(options) {                       
                 var result = {};
                 if (options.filter) {
                     result["filter.logic"] = options.filter.logic;
                     var filters = options.filter.filters;
 
                     for (var idx = 0, length = filters.length; idx < length; idx++) {                               
                         result["filter.filters[" + idx + "].operator"] = filters[idx].operator;
                         result["filter.filters[" + idx + "].field"] = filters[idx].field;
                         result["filter.filters[" + idx + "].value"] = filters[idx].value;                               
                     }                          
                 }                       
                 return result;
             }
         
                            },
                            schema: {
                                model: {
                                    fields: {
                                        AccountName: { type: "string" },
                                    AccountNumber: { type: "string" },
                                        ContractName: { type: "string" },
                                        ContractNumber: { type: "string" },
                                        ContractProductType: { type: "string" }
                                    }
                                }
                            },
                            pageSize: 10,
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        filterable: true,                                               
                        pageable: true,
                        height: 400,                        
                        columns: [
                            { field: "AccountName", title: "Account Name", width: 150 },
                            { field: "AccountNumber", title: "Account Number", width: 150 },
                            { field: "ContractName", title: "ContractName", width: 150 },
                            { field: "ContractNumber", title: "Contract Number", width: 100 }
                        ]
                    });
                });

All I want when any action perfor in grid like sorting,Filtering or paging my "GridCommand command" have that option on server.

How can I modify  parameterMap: function(options) {    } function to send all option on server in GridCommand .



No answers yet. Maybe you can help?

Tags
Grid
Asked by
Anilesh
Top achievements
Rank 1
Share this question
or