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

Multiselect Grid: Deactivate mouse selection

2 Answers 588 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BigzampanoXXl
Top achievements
Rank 1
BigzampanoXXl asked on 02 Sep 2013, 11:11 AM
Hello,

I have a Grid using multiselect. My problem is: The Gridrows should be draggable (which perfectly works without multiselect). If I activate multiselect it doesnt work because the mousedown seems to be a selection mode for the multiselection. Is there any possibility to deactivate the mouse selection without deactivating the multiselect of the grid?

It should only be possible to select with the ctrl-key.

Thank you!

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 04 Sep 2013, 08:41 AM
Hi Dietmar,


In general, overriding the selection behavior to work only on click and not on mouse drag could not be achieved. I would suggest you the following alternative solution - since all that the selection is doing under the hood is adding the k-state-selected class to the specified rows, I would suggest you to disable the grid selection and manually handle it via jQuery i.e. add or remove the class when needed.
E.g.
var selectedClass = 'k-state-selected';
$(document).on('click','#grid tbody tr',function(e) {
  if (e.ctrlKey || e.metaKey) {
    $(this).toggleClass(selectedClass);
  } else {           
    $(this).addClass(selectedClass).siblings().removeClass(selectedClass);
  }
});

An issue that will occur is that the select method of the Grid will not work as expected, so to retrieve the selected rows, you could use the following code snippet.
E.g.
var selected = $("#grid tbody").find("tr.k-state-selected");

For your convenience I prepared a complete JS Bin example. I hope that it will be helpful.

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
BigzampanoXXl
Top achievements
Rank 1
answered on 05 Sep 2013, 10:34 AM
Hi Dimiter,

thanks for your suggestion. I implemented it this way. Works fine for me. The only problem is, that I also have to implement the reaction on a pressed shift-key, manually. But I think I'm gonna solve this by caching the last selected row and then adding the class to all of the items in between. I think this will be the easiest way.

Thanks for your help!
Tags
Grid
Asked by
BigzampanoXXl
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
BigzampanoXXl
Top achievements
Rank 1
Share this question
or