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

Drop into unused portion of grid

17 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JeffN
Top achievements
Rank 1
JeffN asked on 09 Jun 2008, 01:09 PM
I have 2 grids that I'm able to drop rows between. My issue is that when dragging from one to the other, the record has to be dropped on top of an existing record and not in the open area underneath of it (between the existing records and the footer). If I drop into that "open area", the RowDrop event never fires and the move never takes place.

When there are no records in the grid to be dropped into, I have a "NoRecordsTemplate" and a drop occurs without any issues.

Is there a way to make this open area between the last record and the footer a "droppable" area? Do I have to display an image there of some sort (to mock the Recycle Bin functionality in the sample)? If so, how would I do that? Is there javascript somewhere that is cancelling this drop so that the AJAX RowDrop event is never firing?

Note, the drag/drop sample has the same issue.

Thanks!

17 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 11 Jun 2008, 04:53 PM
Hi Jeff,

The RowDrop event is fired every time a row is dropped in RadGrid, unless explicitly canceled as in the online example. A suggestion for you would be check for the destination element of the dropping row in the javascript RowDropping function, and fire the event if the destination element is the second RadGrid:

function onRowDropping(sender, args) 
    var node = args.get_destinationHtmlElement(); 
    if(!isChildOf('<%= RadGrid2.ClientID %>', node)) 
    { 
        args.set_cancel(true); 
    } 

Then on the server, you can check if e.HtmlElement is the second RadGrid, and perform your custom row transfer:

protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e) 
    if (!string.IsNullOrEmpty(e.HtmlElement) && e.HtmlElement == "RadGrid2"
    { 
        // Custom code here 
    } 

If your second RadGrid does not stretch down to the height of the first one (as in the online example), you can simulate this by nesting the grid inside another element with the needed width and height, and then performing the same operations as shown above.

Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JeffN
Top achievements
Rank 1
answered on 12 Jun 2008, 12:48 PM
Thanks. But, I actually ended up fixing it using a different approach. Since a postback wasn't occurring when I dropped into this "open area", I had to add code within the client side "onRowDropping" event. I added the following code:

if (node.id == 'grdWhatever_GridData')

{

__doPostBack(

"<%= btnMoveTo.UniqueID %>", "Click");

}

These grids could have their items moved via drag/drop OR arrow buttons. So, when dropped into the "open area" (aka "Grd_GridData"), I manually do a postback simulating that the "Move To" button was clicked. This event has code that moves the selected item from one grid to the other.

0
Veli
Telerik team
answered on 12 Jun 2008, 04:53 PM
Hi Jeff,

Yes, this is another option implementing the row drag and drop functionality, where a certain destination html element triggers some custom action.

All the best,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alex
Top achievements
Rank 2
answered on 15 Jul 2008, 04:19 PM
I am having the same issue here and what I'm trying to do is on the RowDropped I am trying to do a postback to the RowDrop event of the radGrid.

Is this possible?

My code is simple:

function onRowDropped(sender, args)

{

__doPostBack("<%= rdgCategoryBudget.UniqueID %>", "RowDrop")

}

Please advise.

Thanks

0
JeffN
Top achievements
Rank 1
answered on 15 Jul 2008, 04:23 PM
If that doesn't work, you should at least be able to post back to a button click event like I did. This button click event can then call the RowDrop event. I think you'll lose your event args, but hopefully you can get most of the information you'd need from other properties (selected indexes, etc). You could even make the button that's getting the click event an invisible one if you didn't want the users to see it.
0
Alex
Top achievements
Rank 2
answered on 16 Jul 2008, 06:27 PM
Thanks for the report.

I thought about that and I have a couple of questions with this method.

On the source grid the you can select a row, but if you drag and drop a row without selecting it first the selectedindex is not set.
How do you determine which row they are dragging if they did not do a select of that row prior?

If they simply grab the row they want to drag and drop without selecting it first the selectedindex.count of the grid is always 0 so I can determine which row was selected.

Using the OnRowDropped I could always determine by useing DraggedItems.

How do you handle this.

Thanks
0
Rosen
Telerik team
answered on 18 Jul 2008, 11:23 AM
Hi Alex,

You cannot fire RowDrop server event in such manner. As it will require some arguments to be available in order to be fired correctly.

Best wishes,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JeffN
Top achievements
Rank 1
answered on 18 Jul 2008, 12:24 PM

Alex-

You could do something like I'm doing probably. Here's the code:

Client Side (this seems to need to be in the actual aspx page instead of a separate js file for some reason):
function onRowDropping(sender, args)
{
   if (sender.get_id() == "grdXXX")
 {
  var node = args.get_destinationHtmlElement();
  //If the id is "grdAAA_GridData" then dropped into blank selected area
  if (node.id == 'grdAAA_GridData')
  {
   document.getElementById('<%=hdnSelectedResourceIndex.ClientID %>').value = '';
   __doPostBack("<%= btnMoveTo.UniqueID %>", "Click");
  }                   
 }
}

Button Click Event:
protected void btnMoveTo_Click(object sender, EventArgs e)
{
 if (grdXXX.SelectedItems.Count > 0)
 {
  MoveResourceToSelected(int.Parse(grdXXX.SelectedValue.ToString()));
 }
}


MoveResourceToSelected method:
This has code that moves the selected resource from the "available" to the "selected" list.

Hopefully this helps!

0
Alex
Top achievements
Rank 2
answered on 18 Jul 2008, 07:05 PM
Jeff I am having 2 issues with your solution.

The first as I mentionned if the user grabs a row and drags it without physically selecting it the selectedindexes.count the grid is always 0 or better yet if he does select a row and drags another row instead the selectedindex(0) is that of the selected row and not the row that was drragged.

The second is not an issue but more of a question, this works when you drop it on the empty space of a grid. How do I prevent a double postback when I drop it on a destination row.
Double postback is caused by your code and the second postback caused by the OnRowDrop event of the grid because you did drop it on a valid area?

Thanks
0
JeffN
Top achievements
Rank 1
answered on 18 Jul 2008, 07:09 PM
I'm not sure about the first issue (sorry, don't have time to look into it now)

About the second issue. Here's the complete js code (I only included a portion of it before):

function onRowDropping(sender, args)
{
   if (sender.get_id() == "grdAvailable")
 {
  var node = args.get_destinationHtmlElement();
  //If the id is "grdSelected_GridData" then dropped into blank selected area
  if (node.id == 'grdSelected_GridData')
  {
   document.getElementById('<%=hdnSelectedResourceIndex.ClientID %>').value = '';
   __doPostBack("<%= btnMoveTo.UniqueID %>", "Click");
  }
 
  if(!isChildOf('<%=grdSelected.ClientID %>', node) && !isChildOf('<%=grdAvailable.ClientID %>', node) )
  {
   args.set_cancel(true);
  }
 }
 else if (sender.get_id() == "grdSelected")
 {
  var node = args.get_destinationHtmlElement();
  if(!isChildOf('<%=grdAvailable.ClientID %>', node) && !isChildOf('<%=grdSelected.ClientID %>', node) )
  {
   args.set_cancel(true);
  }
 }
 else
 {
  var node = args.get_destinationHtmlElement();
  if(!isChildOf('trashCan', node))
  {
   args.set_cancel(true);
  }
 }

 //Set hidden field (hdnDragInProgress) back to false      
 var hdnDragStatus = document.getElementById('<%=hdnDragInProgress.ClientID %>');
 hdnDragStatus.value = "false";
}

0
Alex
Top achievements
Rank 2
answered on 18 Jul 2008, 07:13 PM
No problem on the first issue and thanks for the full code.

I'm hoping a Teleriky (or is that a Telerikian) will explain why when you drag a row when you have a select column the selectedindex.count is 0 unless you specifically click on the select column first.

Not that is has that much impact, it's just bizarre.
0
Rosen
Telerik team
answered on 21 Jul 2008, 11:31 AM
Hello Alex,

I'm not sure I understand you correctly. You cannot drag a row without selecting it first. If you have multi-row selection enabled, you should first select row(s) and then you can drag them. Or if you have single-row selection the row is automatically selected when dragged.

Can you please provide (attached to a formal ticket) a sample demo in which this behavior can be reproduced? Thus I will do my best to advice you further.

Best regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Alex
Top achievements
Rank 2
answered on 21 Jul 2008, 03:54 PM
I will create a demo project and submit it with a formal ticket.

I can most definitly drag/drop without first selecting the row(s), but then it really depends on your definition of selecting.

I can grap a row and drag/drop it without prior explicitly selecting it in this case the selectedindexes.count is 0, but the draggeditems object is correct (so I always use the draggeditems and ignore the selectedindexes).

Another scenario is if I select a row and then dragged another row, the selectedindexes(0) is not the same as the draggeditems(0). Again I always use the draggeditems object because it is alway right.

0
Sebastian
Telerik team
answered on 22 Jul 2008, 06:03 AM
Hi Alex,

Feel free to submit the sample project once you assemble it. We will review it and will get around to you with our findings.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Doug Beard
Top achievements
Rank 1
answered on 01 Oct 2009, 07:58 PM
FYI it appears that the OnRowDrop event will not fire when the row is dropped on the header of a grid.
Puzzling!!  It took me 2 hours to figure out why the event was not firing.  If the grid is empty (no data), there is precious little real-estate to drop upon.  It becomes quite possible that a user would drop upon the header.
0
Sebastian
Telerik team
answered on 02 Oct 2009, 08:36 AM
Hello Doug,

In such case you can expand height of the no records item as shown in the second grid of the corresponding online demo of RadGrid for ASP.NET AJAX:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/draganddrop/defaultcs.aspx

You may also added a user-friendly message to clarify where grid records can be dropped to prevent the confusion.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Doug Beard
Top achievements
Rank 1
answered on 07 Oct 2009, 02:03 PM
Thanks for your reply.  I took similar steps, in that I wrap the grid in another element (div or radpane or whatever) and use it as destination for clientside drop checks, so that there is plenty of space available for the user.  I would, however, like to see the grid header accept drops, in future iterations.
Tags
Grid
Asked by
JeffN
Top achievements
Rank 1
Answers by
Veli
Telerik team
JeffN
Top achievements
Rank 1
Alex
Top achievements
Rank 2
Rosen
Telerik team
Sebastian
Telerik team
Doug Beard
Top achievements
Rank 1
Share this question
or