Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor webgrid ajax paging and sorting

I'm trying to learn how to use Razor WebGrid in MVC3. How does the ajaxUpdateCallback parameter work?

like image 881
Sean Cain Avatar asked Dec 03 '10 04:12

Sean Cain


2 Answers

The ajaxUpdateCallback is the name of the javascript function that will get called after the server call is complete. The title of your question is regarding paging and sorting with the WebGrid which would look something like this...

@{
    var grid = new WebGrid(canPage: true, rowsPerPage: ThisController.PageSize, canSort: true, ajaxUpdateContainerId: "grid");
    grid.Bind(Model.Employees, rowCount: Model.TotalRecords, autoSortAndPage: false);
    grid.Pager(WebGridPagerModes.All);
    @grid.GetHtml(htmlAttributes: new { id="grid" },
        columns: grid.Columns(
            grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { EmployeeID = item.EmployeeID })),
            grid.Column("FullName"),
            grid.Column("Title")
        ));
}

I have a full example here if you'd like to see it:

Example

like image 129
Sean Chase Avatar answered Oct 30 '22 21:10

Sean Chase


The ajaxUpdateCallBack parameter is used to specify the JavaScript function that should be called when the element denoted by the ajaxUpdateContainerId value has been updated as a result of sorting or paging etc. You pass it into the constructor like this:

var grid = new WebGrid(data, ajaxUpdateContainerId : "grid", 
                ajaxUpdateCallback: "callBack");

And it will point to this:

function callBack(){
    alert('Called Back');
}
like image 38
Mike Brind Avatar answered Oct 30 '22 22:10

Mike Brind