28

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

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
Sean Cain
  • 898
  • 2
  • 10
  • 16

2 Answers2

47

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

Sean Chase
  • 1,139
  • 1
  • 15
  • 23
  • 3
    Very nice example page for an awesome little thing. Just what I needed at the end of a long sprint to throw up that last page of data before I sleep for 30 hours. LOL, much appreciated. – MvcCmsJon Feb 18 '11 at 15:07
15

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');
}
Mike Brind
  • 28,238
  • 6
  • 56
  • 88