mercredi 29 novembre 2017

How can i select all rows using pagesize on Kendo

I have checkbox which must select entire grid rows. Once a user click select all, It must select all pages on the grid.

Now i can get the length of the rows on the grid but only one checkbox get checked. How can i get all check box clicked since i can get the length?

Here is my code:

 function checkAll(ele)
    {

        var grid = $("#Grid1").data("kendoGrid");
        grid.dataSource.pageSize(grid.dataSource.data().length);
        console.log("Length" + grid.dataSource.data().length);

        var dataArea = gridElement.find(".k-grid-content");
        var gridTest = $('#Grid1 .checkbox');

        for (var i = 0; i < gridTest.length; i++) {
            var isChecked = $('#masterCheckBox').is(':checked')//!$(this).is(':checked');
            alert("isChecked" + isChecked);
            if (isChecked) {
                $('#Grid1.checkbox').prop('checked', 'checked');
                break;
            }
        };
    };

Kendo grid

<div>

            @(Html.Kendo().Grid<model>()
            .Name("Grid1")
                  .Columns(columns =>
                  {
                  columns.Bound(x => x.roleName).Title("Role Names");
                  columns.Template(@<text></text>).ClientTemplate("<input type='checkbox' #= selected ? checked='checked':'' # class='checkbox' />")
                                              .HeaderTemplate("<input type='checkbox' class='checkbox' id='masterCheckBox' onclick='checkAll(this)'/>")
                                              .Width(30);
                  })

                  .Pageable(pageable => pageable
                    .Refresh(true)
                    .PageSizes(true)
                    .ButtonCount(5))
                  .Scrollable()
                  .Filterable()
                  .Sortable()

                  .Resizable(resize => resize.Columns(true))
                  .DataSource(dataSource => dataSource
                  .Ajax()
                  .PageSize(10)
                  .ServerOperation(false)
                  .Read(read => read.Action("", ""))))


        </div>




Aucun commentaire:

Enregistrer un commentaire