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

How to only allow user selecting two grid rows ?

1 Answer 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Daochuen asked on 11 Feb 2019, 09:04 PM
The business logic in my MVC project only allow user selecting two rows. I tried couple of ways but no success solution yet. Does anyone have idea about this ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 13 Feb 2019, 01:12 PM
Hello Daochuen,

A possible solution would be to attach a click handler to the row and check for the count of the selected rows. If there are already two rows selected prevent the user from selecting another one.

e.g.

$('#grid tbody tr').on('click', function (e) {
  var grid = $('#grid').data('kendoGrid');
  debugger
  if (grid.select().length >= 2 && !$(e.currentTarget).is('.k-state-selected')) {
 
    e.preventDefault();
    e.stopPropagation();
  }
})

Below you will find a small sample which demonstrates the above approach:


Even though the sample uses a jQuery grid, as the logic is on the client, the very same approach applies for a grid configured with the server wrappers.


Regards,
Georgi
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.
Tags
Grid
Asked by
Daochuen
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Georgi
Telerik team
Share this question
or