This is a migrated thread and some comments may be shown as answers.

Selecting Multiple records in grid with checkboxes Issue

3 Answers 331 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 26 Sep 2018, 01:31 PM

I have a Kendo Grid in an MVC view.  I've enabled paging, and added a check box to select the records.  Everything seems to work, however when I select all items on 1 page, for some reason, all items get selected across all pages instead of just on the 1 page.  If I select all items only on 1 page - all items in all subsequent pages should not be checked.  Any ideas?

@(Html.Kendo().Grid(Model.ResultFiles)
                          .Name("Grid")
                          .Columns(columns =>                           {
                              columns.Select().Width(50);
                              columns.Bound(r => r.Id).Hidden();
                              columns.Bound(r => r.SomeNumber).Title("Number").Filterable(f => f.Cell(cell => cell.ShowOperators(false))).ClientTemplate("#= SomeNumber# # if(!Viewed) { # <span id='unread-#= Id #' class='badge new-results'>New</span> # } #");
                              columns.Bound(r => r.Name).Title("Person").Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
                              columns.Bound(r => r.DateOfBirth).Title("Date of Birth")
                                  .ClientTemplate("#= DateOfBirthAsString#")
                                  .Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
                              columns.Bound(r => r.CompanyName).Hidden();
                              columns.Bound(r => r.SomeOtherName).Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
                              columns.Bound(r => r.DisplayName).Title("Place").Filterable(f => f.Cell(cell => cell.ShowOperators(false)));
                              columns.Bound(r => r.EntryDateAsString).Title("Collection Date").Filterable(false);
                              columns.Bound(r => r.ReportGuid).Hidden(true);
                          })
                          .ToolBar(t => t.Template(@<text><label>Search By Entry Date Range:</label>                                 <div class="row">                                     <div class="col-md-3">@(Html.Kendo().DatePicker().Name("startSearch").HtmlAttributes(new { PlaceHolder = "Start Date..." }))</div>                                     <div class="col-md-3">@(Html.Kendo().DatePicker().Name("endSearch").HtmlAttributes(new { PlaceHolder = "End Date..." }))</div>                                     <div class="col-md-1"><button class="k-button" type="button" onclick="filterGrid()" style="width: 100%">Search</button></div>                                     <div class="col-md-1"><button class="k-button" type="button" onclick="resetFilter()" style="width: 100%">Reset</button></div>                                     <div class="col-md-1"><button class="k-button" type="button" onclick="downloadFiles()" style="width: 100%">Download</button></div>                                 </div></text>))
                            .Pageable(p => p.PageSizes(new int[] { 10, 25, 50, 100 }))
                            .Sortable()
                            .Filterable(ftb => ftb.Mode(GridFilterMode.Row)
                                .Operators(o => o
                                    .ForString(str => str.Clear()
                                        .Contains("Contains")
                                    )
                                )
                            )
                            .DataSource(dataSource => dataSource
                                .Ajax()
                                .Sort(sort => sort.Add("EntryDate").Descending())
                                .Read(read => read.Action("Search", "Reports"))
                                .PageSize(10)
                            )
                            .PersistSelection()
                        )

3 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 26 Sep 2018, 04:02 PM
And when I say "select all items on 1 page" - I mean I'm selecting all items individually - not by clicking the Select All checkbox in the grid header.
0
Accepted
Konstantin Dikov
Telerik team
answered on 28 Sep 2018, 07:39 AM
Hi Jason,

The behavior that you are describing is not expected and I am guessing that there is some custom logic that handles the change event of the "Check all" checkbox and selects the records on all pages. However, please note that in order for the PersistSelection to work correctly, you need to define the ID field in the DataSource's schema, because this is the value used for persisting the selection. From the provided code snippet it seems that you will have to add the following:
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.Id))

Additionally, if you have custom logic for selecting all records when the "Check all" checkbox is clicked, you will have to either remove it or ensure that you are applying it only when the checkbox is clicked.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jason
Top achievements
Rank 1
answered on 28 Sep 2018, 12:58 PM
That was it - specifying the id field solve the issue.  Thank you very much!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or