imagemodel-view-controllerpaginationwebgrid

I want to call loader image when I click sorting and paging for MVC webgrid?


I create a div and tried calling Jquery like loader.show(). But not sure how to trigger it when I page or sort the mvc webgrid?

My web grid:

 <div id="grid">
@{
    var grid = new WebGrid<MemberSearch>(ajaxUpdateContainerId: "grid",
       rowsPerPage: Model.PageSize, defaultSort: "LastName");
    grid.Bind(Model.Member, rowCount: Model.TotalRows, autoSortAndPage: false);
    // NOTE: I've created another html helper to allow a server-paged grid to be rendered in one call (complete with compiler type inference) as shown below
    //var grid = Html.ServerPagedGrid(Model.Products, Model.TotalRows, rowsPerPage: Model.PageSize);
}
@grid.GetHtml(tableStyle: "webgrid",
            headerStyle: "webgrid-header",
            footerStyle: "w-footer",
            alternatingRowStyle: "webgrid-alternating-rows",
                columns: grid.Columns(
                grid.Column(format: @<text>@Html.ActionLink("Edit", "Edit", new { Id = item.Id }) </text>),
                grid.Column("fullname", header: "Name", format: @<text>@item.fullname</text>),
                grid.Column("Email", header: "Email", format: @<text>@item.Email</text>),
                grid.Column("companyname", header: "Company", format: @<text>@item.companyname</text>),
                grid.Column("regDate", header: "Registration Date", format: @<text>@item.regDate</text>),
                grid.Column("country", header: "Country", format: @<text>@item.country</text>),
                grid.Column("modifiedDate", header: "Profile Modified", format: @<text>@item.modifiedDate</text>),
                grid.Column("ciscontactid", header: "CIS ID", format: @<text>@item.ciscontactid</text>)
                         )
                 )

</div>

Solution

  • In your document.ready add the following:

    $('thead > tr > th > a[href$="sort"]').click(function () {
       loader.show() 
    });
    

    This will select the th tags and the a tags that the WebGrid getHtml generates for you. This will handle when the grid is sorted.