Rocky
Rocky

Reputation: 4524

WebGrid Paging not working

I have a dropdown and button control, on button click I am binding the WebGrid, which is working fine, on load grid will be empty, but after binding the grid paging is not working, below is my code

@using (Html.BeginForm("EmpLog", "Labels", FormMethod.Post))
{
  @Html.DropDownListFor(x => x.SelectedValue, Model.Values, "----Select----", new { id = "ddlName", @class = "form-control col-md-6" })
  <input type="submit" value="Search" id="btnSearch" class="btn btn-default" />

  @{
     var gridview = new WebGrid(source: Model.LstLog, rowsPerPage: 20, ajaxUpdateContainerId: "grid", canSort: false);
   }

  @if (Model.Lst != null)
   {
     @gridview.GetHtml(
                  htmlAttributes: new { id = "gridlogs" },
                  fillEmptyRows: false,
                  alternatingRowStyle: "alternate-row",
                  headerStyle: "grid-header",
                  footerStyle: "grid-footer",
                  selectedRowStyle: "grid-selected-row",
                  rowStyle: "grid-row-style",
                  mode: WebGridPagerModes.All,
                  firstText: "<< First",
                  previousText: "< Prev",
                  nextText: "Next >",
                  lastText: "Last >>",
                  columns: new[] {
                  gridview.Column("View", header: null, style: "click_able", format: @<text><a href="javascript:ViewFullDetails('@item.Id');">View</a></text>, canSort: false),
                  gridview.Column("JoinDate",header: "Join Date"),
                  gridview.Column("DeptName",header: "Dept Name"),
                  gridview.Column("Project",header: "Project")
                 }
             )}
    }

    [HttpGet]
    public ActionResult EmpLog()
    {
         model.Values = GetDDLInfo();
         return View();
    }

    [HttpPost]
    public ActionResult EmpLog()
    {
         model.Values = GetDDLInfo();
         model.LstLog= GetLogInfo();
         return View(model);
    }

I am not good enough with WebGrid, Please help me to apply paging in that.

Upvotes: 2

Views: 570

Answers (1)

Rocky
Rocky

Reputation: 4524

I have added below code to work paging

$('th a, tfoot a').click(function () {
    $('form').attr('action', $(this).attr('href')).submit();
    return false;
});

Upvotes: 1

Related Questions