How to check all Checkboxs on my Grid? Not just the first pagination

Asked

Viewed 26 times

3

 var grid = new WebGrid(
          canPage: true,
        rowsPerPage: 10,
        selectionFieldName: "selectedRow",
        ajaxUpdateContainerId: "gridViewCV",
        ajaxUpdateCallback: "ajaxWebGrid");

var columns = new List<WebGridColumn>()
  {
    grid.Column("IdUsuario", "Candidato", canSort: false, format:  @<text>@((item.Usuario_ID))</text>, style: "hidden"),
    grid.Column("IdUsuario", "CheckX", canSort: false, format: (item) => new HtmlString(Html.Raw(Html.CheckBox("CheckUsuario", false, new {id = item.Usuario_ID }) ).ToString())),
    grid.Column("vlNotaDISC", "DISC", canSort: true, format: (item) => new HtmlString(Html.Raw(item.HTMLDISC).ToString()), style: "text-align-center hidden-xs"),
  };

     @MvcHtmlString.Create(
              grid.GetHtml(
                      htmlAttributes: new { id = "gridViewCV" },
                      tableStyle: "table-grid table table-hover table-striped webgrid-table",
                      headerStyle: "table-header-grid default-bg",
                      footerStyle: "table-footer-grid jQ-gridFooter",
                      rowStyle: "table-linha-grid table-linha-grid-alternate",
                      alternatingRowStyle: "table-linha-grid",
                      mode: WebGridPagerModes.All,
                      lastText: "»»",
                      firstText: "««",
                      nextText: "»",
                      previousText: "«",
                      numericLinksCount: 10
                      columns: grid.Columns(columns.ToArray())).ToString()));

J functions

<script>

           $(document).ready(function () {
             ajaxWebGrid();
        });


      function CheckAllContas(source) {
        var checkboxes = document.getElementsByName('CheckUsuario');
        for (var i = 0, n = checkboxes.length; i < n; i++) {
        
            checkboxes[i].checked = source.checked;
        }
    }



      $('#table-content table th').each(function () {
            if (this.innerHTML.indexOf("CheckX") > -1) {
                this.innerHTML = "<input id=\"CheckAllContas\"type=\"checkbox\">";

                $('#CheckAllContas').change(function () {  
                    CheckAllContas(this);
                });
            }
     });

      </script>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.