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

Send additional data as parameters in Kendo Grid while using server side sorting

1 Answer 1041 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shivasai
Top achievements
Rank 1
shivasai asked on 12 Aug 2014, 02:00 PM
Hi, I am using Kendo Grid in my application with Server side sorting. I am sending additional data(object) to my method.

var viewModel = kendo.observable({
        param: {
            LeadName: "",
            LeadPriority: 1,
            Notes: "",
            Address: "",
            City: "",
            State: "",
            Zip: "",
            Booked:  1,           
            SearchText: ""
        }
});

$("#leadsGrdView").kendoGrid({
        dataSource: {
            type: "aspnetmvc-ajax",
            transport: {
                read: {
                    url: "Lead/GetLeadListResult",
                    data: JSON.parse(JSON.stringify(viewModel.param))
                }
            },
            schema: {
                model: {
                    fields: {
                        Name: { type: "string", editable: false },
                        Priority: { type: "string", editable: false },
                        Notes: { type: "string" },
                        Booked: { type: "checkbox", editable: false },
                        Address: { editable: false },
                        Id: { type: "int" }
                    }
                },
                total: "Total",
                data: "Data"
            },
            pageSize: 10,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        },
        scrollable: false,
        sortable: true,
        groupable: false,
        pageable: { buttonCount: 4 },
        columns: [{ template: '<a href="/Lead/LeadDetail/#=Id#">#=Name#</a>', field: "Name", title: "Lead Name", width: "30%" },
                  { field: "Priority", title: "Lead Priority", width: "20%" },
                  {
                      field: "Address",
                      title: "Address", width: "30%",
                      template: '<span> #=Address.Address1#, #=Address.City# #=Address.State# </span>'
                  },
                  { field: "Notes", title: "Notes", width: "30%" },
                  {
                      field: "Booked",
                      template: '<input type="checkbox" #= Booked ? "checked=checked" : "" # ></input>'
                  }
        ]
    });

I am using viewModel.param object in my view. I am sending viewModel.param object as an additional data to the method.I can able to retrieve additional data to my method. This works as expected till now. After viewModel.param object variables are modified and if I try to sort any column, the updating additional data is not being sent to method, instead it sends the initial data when Kendo grid is initially loaded. 
How can I send the updated additional data in Server side sorting? Is there any better approach than this to accomplish my requirement.
All I need is to send the updated object I have in my javascript to the method in the controller when using server side sorting. 
Any help will be greatly appreciated

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Aug 2014, 08:58 AM
Hi Shivasai,

Please define the data as a function. In this way it will be evaluated every time a new read request is being started.

transport: {
    read: {
        url: "Lead/GetLeadListResult",
        data: function() { return JSON.parse(JSON.stringify(viewModel.param)); }
    }
},

I hope this approach will fit in your scenario.

Regards,
Alexander Valchev
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
shivasai
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or