Passing parameters to telerik asp.net mvc grid

GlobalCompe picture GlobalCompe · Apr 6, 2010 · Viewed 26.1k times · Source

I have a telerik asp.net mvc grid which needs to be populated based on the search criteria the user enters in separate text boxes. The grid is using ajax method to load itself initially as well as do paging.

How can one pass the search parameters to the grid so that it sends those parameters "every time" it calls the ajax method in response to the user clicking on another page to go to the data on that page?

I read the telerik's user guide but it does not mention this scenario. The only way I have been able to do above is by passing the parameters to the rebind() method on client side using jquery. The issue is that I am not sure if it is the "official" way of passing parameters which will always work even after updates. I found this method on this post on telerik's site: link text

I have to pass in multiple parameters. The action method in the controller when called by the telerik grid runs the query again based on the search parameters.

Here is a snippet of my code:

$("#searchButton").click(function() {
    var grid = $("#Invoices").data('tGrid');

    var startSearchDate = $("#StartDatePicker-input").val();
    var endSearchDate = $("#EndDatePicker-input").val();

    grid.rebind({ startSearchDate: startSearchDate ,
                    endSearchDate: endSearchDate
                });
});

Answer

Craig Fisher picture Craig Fisher · Mar 9, 2011

So according to Telerik "recommended approach is to set the arguments in the onDataBinding event".

function onGridBinding(e) {
if (cancelGridBinding) {  
    // ...
}
else {
    var searchValue = 'something';
    e.data = { search: searchValue };
}

}