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

Undraggable rows

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 12 Feb 2009, 06:15 PM
We have a page with a pair of grids - one containing selected items and one containing items that have not been selected.

We want to allow dragging within the grid of selected items, to allow for reordering, and we want to allow for dragging between the grids to allow items to be selected or unselected.

The complication is that we have a few items that we do not want to be draggable.  They should appear at the top of the grid of selected items, and they should stay there.  The user should not be able to drag them to another locating in the selected items grid, and the user should be able to drag them to the unselected items grid.  In other words, the user should not be able to unselect them or to reorder them.

Any advice as to how accomplish this?  There is an invisible GridBoundColumn in the grid called "Fixed" containing "True" or "False".  I've tried using this in OnItemDataBound to set item.Enabled = false, and the appropriate rows are appearing greyed out in the grid.  But I can still drag the disabled rows.

Any ideas?

1 Answer, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 12 Feb 2009, 07:23 PM
OK., I've figured it out.

First, you have to connect OnRowCreated(), because otherwise get_gridDataItem() doesn't work.

Then you connect OnRowSelecting(), and it it, you access the element and check if it's disabled.  If it is, you call set_cancel(true);

<script type="text/javascript"
   function onRowCreated(sender, args) { 
      // This is here so that the get_gridDataItem() works. 
   } 
 
   function onRowSelecting(sender, args) { 
      var item = args.get_gridDataItem(); 
      var element = item.get_element(); 
      if (element.disabled) 
         args.set_cancel(true); 
   } 
</script> 
 
... 
 
<telerik:RadGrid runat="server" ID="grdSelected" ... > 
   <MasterTableView DataKeyNames="columnname" TableLayout="Fixed"
      <Columns> 
         ... 
      </Columns> 
   </MasterTableView> 
   <ClientSettings AllowRowsDragDrop="True"
      <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" /> 
      <ClientEvents
         OnRowCreated="onRowCreated" OnRowSelecting="onRowSelecting" /> 
   </ClientSettings> 
</telerik:RadGrid> 
 

Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Share this question
or