I am new to SlickGrid, but loving how it looks and feels.
I have two SlickGrids on a page, both are being fed by JSON from a back end MVC controller. This is working fine (though I have a slight formatting issue, but I'm sure I will figure that bit out).
I want to be able to drag and drop between grids... however, the drop doesn't "add" to the grid, it should cause a post to my server showing what from grid 1 was dropped onto what from grid 2. Imagine if you will...
First grid has a list of users Second grid has a list of roles.
I would like to drop a user onto a role, then post back to the server, which user was dropped onto which role. (It will also work the other way... drop a role onto a user, to give the user the role - same result, different drop)
Following https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example9-row-reordering.html, I have it partly working. Took me a while to even get this far. I can drag from one grid, but have absolutely NO IDEA on how to make the second grid accept the drop, never mind how the second grid could even tell what has been dropped from the first.
How do I make the second grid accept a drop? How do I get the details of what was dropped?
In the JS for the grid that I am trying to drop into, I have...
rolegrid.onMouseEnter.subscribe(function (e) {
var cell = rolegrid.getCellFromEvent(e);
console.log('-' + cell.row);
//grid.setSelectedRows([cell.row]);
dropRow = roleslickdata[cell.row].RoleName;
console.log(cell.row + ' : ' + roleslickdata[cell.row].RoleName);
e.stopPropagation();
});
rolegrid.onMouseLeave.subscribe(function (e) {
var cell = rolegrid.getCellFromEvent(e);
console.log('OUT-' + cell.row);
//grid.setSelectedRows([cell.row]);
dropRow = null;
console.log('Leaving ' + cell.row + ' : ' + roleslickdata[cell.row].RoleName);
e.stopPropagation();
});
rolegrid.onDragEnd.subscribe(function (e) {
var cell = rolegrid.getCellFromEvent(e);
console.log('DragEnd-' + cell.row);
//grid.setSelectedRows([cell.row]);
e.stopPropagation();
});
Now... the onDragEnd doesn't appear to be firing, I am assuming this is because the drag start doesn't start here.
The onMouseEnter and onMouseLeave appear to be intermittent at firing... and the very moment that when onMouseEnter does fire, onMouseLeave also fires, so I can't rely on this.
Any ideas at all would be most helpful.
Just so as you know, it won't be just 2 grids on the page, ultimately, there could be many more, and I will want each one to be draggable and each one to accept a drop from another grid.
Thank you for your help.
Following on from above... still experimenting. I have tried using a formatter but that didn't work. However, I did notice something quite odd, in that when the item I was dragging lagged the mouse, it would fire the onMouseEnter and onMouseLeave events... this was the cause of the intermittent behaviour. (I had the mouse pointer 10px inside the top/left of the item I was dragging).
So, changing...
grid.onDrag.subscribe(function (e, dd) {
dd.helper.css({ top: e.pageY - 5, left: e.pageX - 10 });
});
to have e.pageX + 10, I could get the onMouseEnter and onMouseLeave to fire pretty much every time. However, I don't think this is ideal really... as it just feels a little strange as when you drag something in Windows, the mouse pointer is always inside the item you are dragging.
I will continue on this route, but if anyone has any further suggestions that might help, it would be appreciated.
Thank you.