All posts

Telerik RadGrid client-side data-binding using jQuery

Instead of traditional ASP.NET AJAX approach for "Exposing Web Services to Client Script" you can use jQuery and JSON2 JavaScript libraries to achieve the same very easily.

Using this simple method you can call any page method in ASP.NET Page or WebService method:

function executeMethod(location, methodName, methodArguments, onSuccess, onFail) {
    $.ajax({
        type: "POST",
        url: location + "/" + methodName,
        data: methodArguments,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

 

Here is an example also how to use JSON2 JavaScript library to serialize any JavaScript object to string:

function getRequestData(tableView) {
    return JSON.stringify({
        "startIndex": tableView.get_currentPageIndex(),
        "maximumRows": tableView.get_pageSize(),
        "sortExpression": tableView.get_sortExpressions().toString(),
        "filterExpression": tableView.get_filterExpressions().toDynamicLinq()
    });
}

 

And to use these two to bind RadGrid you can simply call:

executeMethod("WebService.asmx", "GetData", getRequestData(tableView), updateGrid);

 

The result: Blazing fast and responsive AJAX DataGrid:

Untitled

[Download]

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Comments  5

  • 10 Oct 2008

    Hello Vladimir, Interresting example but I'd like to know the interest of using jQuery in this case. Since we are already loading ASP.NET AJax client library (because of Script Manager + RadGrid) what is the benefit of using jQuery? Thanks, Laurent

    Laurent

  • 10 Oct 2008

    Hi Laurent, The main benefit is that you will not get extra JavaScript serialized from the ScriptManager (because of EnablePageMethods or ServiceReference) and you have simple universal way to call both page and web service methods. Vlad

    Vlad

  • 21 Oct 2008

    Hi Vlad, When binding a datetime column using jQuery the data is displayed as /Date{numbershere}/ rather than a string representation of the date. Is that a limitation of this method of binding or am I just missing something? Thanks, Tony

    Tony

  • 03 Dec 2009

    Hello Vlad, Is it possible return DataSet/DataTable from WebService for client databinding.

    Sivarajan

  • 04 Dec 2009

    Hi Sivarajan,

    Most probably the framework will unable to serialize these objects due to circular references.

    Vlad

    Vlad

Post a comment
  1. Formatting options
       
     
     
     
     
       
  2. Security image