title: How to select all rows from Kendo grid using checkbox on header
body: <p>I have select all checkbox on a Kendo Grid. This checkbox only selects first page and when you move to page to it is not selected. All I want is to use the checkbox to select all the rows from the grid. If the rows returned on the grid are 500, all of them must be selected by one click which is the checkbox. I have tried a lot of examples from but not getting it to work on MVC Razor.</p>
  
  <p>I have tried many examples like this <a href="https://docs.telerik.com/kendo-ui/knowledge-base/checkbox-selection-select-all-rows-all-pages" rel="nofollow noreferrer">Example</a> </p>
  
  <pre><code>@(Html.Kendo().Grid&lt;Model&gt;()
                  .Name("Grid")
                  .ToolBar(toolBar =&gt; toolBar.Template("&lt;strong&gt;&lt;a className='k-grid-toolbar-create' onClick='goToFunctionDownloadAllIpossFile()' href ='" + Url.Action("GetFileFromSession", "ConsolidatedPOSS", "https") + "?SeletectOrders=#= SeletectOrders#'" + "&gt;&lt;button type='button' class='btn btn-primary'&gt; Download Selected Orders &lt;/button&gt;&lt;/a&gt;&lt;/strong&gt;"))
                  .Columns(columns =&gt;
                  {
                  columns.Bound(x =&gt; x.ordernumber).Title("Order Number");
                   columns.Template(@&lt;text&gt;&lt;/text&gt;).ClientTemplate("&lt;input type='checkbox' id='chkId' #= selected ? checked='checked':'' # class='checkbox' /&gt;")
                  .HeaderTemplate("&lt;input type='checkbox' class='checkbox1' id='checkAll1' onclick='checkAll(this)'/&gt;").Width(50);
                  })
                  .Pageable(pageable =&gt; pageable
                  //.Refresh(true)
                  .PageSizes(true)
                  .ButtonCount(5))
                  .Scrollable()
                  .Filterable()
                  .Sortable()
                  .Resizable(resize =&gt; resize.Columns(true))
                  .DataSource(dataSource =&gt; dataSource
                  .Ajax()
                  .PageSize(10)
                  .ServerOperation(false)
                  .Read(read =&gt; read.Action("Action", "Controller"))))
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>function checkAll(ele) {
      alert();
      var state = $(ele).is(':checked');
      grid = $('#Grid').data('kendoGrid');
  
      datasource = grid.dataSource.view();
      //dataSource.pageSize(dataSource.total());
      $.each(grid.dataSource.view(), function ()
      {
          if (this['selected'] != state)
          {
              this.dirty = true;
          }  
          this['selected'] = state;
      });
      grid.refresh();
  }
  </code></pre>