0

I'm using dnd on a 120px tall dgrid and it's nearly impossible to hit my drop target. The default auto-scroll feature is too fast for this small grid. Is there a way to set an acceleration value or correlate the scroll speed with the closeness to the grid edge?

So far I've found dojo.dnd.autoscroll but those properties seem unrelated to scroll speed.

One solution is to modified autoscroll.js directly by changing autoScrollNodes:

// injected acceleration logic
if(ry > 0 && ry < b.h){
    if(ry < h){
        dy = -h * (1.0 - ry / h);
    }else if(ry > b.h - h){
        dy = h * (1.0 - (b.h-ry) / h);
    }
    oldTop = n.scrollTop;
    n.scrollTop  = n.scrollTop  + dy;
}
Corey Alix
  • 2,694
  • 2
  • 27
  • 38
  • So you want it to scroll, just not as fast? I believe the properties in dojo/dnd/autoscroll you mention handle when autoscroll fires, not how fast. Off hand, I think I would try monkey patching Manager's onMove to throttle the autoscroll for particular drop targets. But before I add any answer, I'd like to replicate what you're describing. Can you post your code? – bishop Oct 30 '13 at 23:29
  • I'll look into the Manager...don't know what that it presently. Here's an only example. Just drag a row and try to drop it on a row down a little in the grid. http://dojofoundation.org/packages/dgrid/js/dgrid/test/extensions/DnD.html – Corey Alix Oct 31 '13 at 01:18
  • Hadn't eaten in like 7 hours: meant to say [Moveable](https://dojotoolkit.org/reference-guide/1.9/dojo/dnd.html#moveable) not manager. I'll check that code link when I get in tomorrow, thanks! – bishop Oct 31 '13 at 01:49
  • So, in that example's first table, if you drag "grue" downward toward "make balls" and try to drop it above or below "make balls", the table scrolls upward too fast? – bishop Oct 31 '13 at 14:05
  • Yes. In this case the grid is much larger than the scroll amount so as long as you steady your hand you can stop moving the mouse and hit your target. In my case I only have a few rows showing in the grid and it's truly impossible to hit the target. The code above seems to be working for me without needing to throttle mouseMove and has the added advantage of allowing fast scrolling if I want it by moving the cursor near the grid edge. – Corey Alix Oct 31 '13 at 20:54
  • Check out [this fiddle](http://jsfiddle.net/6Gbhg/1/), which is the smallest test case I could make. (The fiddle doesn't work out of the box: you need to setup dgrid packages.) The grid is 100px high and has 1000 elements, which shows 3 rows at a time. If I drag my mouse down, the rows scroll up at a manageable pace. If I want to go faster, I rapidly move my mouse up and down. (In Chrome.) What dojo version & browser? (I'd like my answer to be relevant to the actual problem, rather than speculating on the design aspect.) – bishop Nov 03 '13 at 02:49
  • I don't see what part of that fiddle is relevant to this problem. – Corey Alix Nov 04 '13 at 15:22
  • I'm trying to replicate "squirrel-like", which I've interpretted as meaning "scrolls too fast when near an edge". In my fiddle, I setup a scenario where there is a short grid (100px) and a lot of rows (1000) with DnD enabled. I drag a row from top toward bottom and the scrolling accelerates as I expect (slowly). You linked to the dojo test case, and I see that it moves a little different than my example, but is still usable for me. So, so far, I cannot replicate. Until then, Im reluctant to answer, but I can suggest that autoscroll.js isn't meant to be monkey-patched. – bishop Nov 04 '13 at 15:50

0 Answers0