Telerik grid client side databinding with additional parameters

Scenario: I got a Telerik grid, required to use client side binding, and it provide the search ability to allow user to filter the grid result, how can I achieve this?

  1. Specify SelectMethod and Location under the DataBinding section
  2. Construct your method to Select your data

example: lookup a person with first name and last name

method signature: public List<Person> lookupPerson(string firstName, string lastName)

  1. Under the ClientSettings section, add the ClientEvents section in
  2. Add the onDataBinding event in the ClientEvents

Code snippet

<ClientSettings>
<ClientEvents OnDataBinding=”onPersonLookupDatabinding” />
<DataBinding SelectMethod=”lookupPerson” Location=”\Services\PersonLookup.svc”>
</DataBinding>
</ClientSettings>

So, there are no option to put in firstName and lastName ?!?! Oh wait! How come I didn’t mention about what is in the OnDataBinding Event, that is a client side JavaScript to allow you to add in all the custom parameter

Code snippet

function onPersonLookupDatabinding(sender, args) {
try {
var fn = $(“#txtFirstName”).val();
var ln = $(“#txtLastName”).val();
var methodArguments = args.get_methodArguments();
methodArguments.firstName = fn;
methodArguments.lastName = ln;
args.set_methodArguments(methodArguments);

}
catch (e) { }
}

This code read the user input, and passing into the method once it’s trying to call the web service request for data.

Advertisements