Fixes some bugs for ng-grid-reorderable

ng-grid-reorderable is a drag-drop plugin for ng-gird. I found some bugs when I was using this plugin.

###Bug 1: It doesn’t work on firefox
The plugin use html5 drag-drop, firefox needs to set data for dataTransfer.

1
2
3
4

var onDragStart = function (event) {
event.originalEvent.dataTransfer.setData("gridId", self.myGrid.gridId);
};

###Bug 2: Can drag a row to the other ng-grid
To fix this bug, it needs to compare grid id on drop event.

1
2
var prevRow = self.services.DomUtilityService.eventStorage.rowToMove;
if (prevRow.gridId != self.myGrid.gridId) return;

###Bug 3: Can’t select all texts when at edting status
To fix this bug, it needs to disable drag-drop feature.

1
2
3
4
5
6
7
8
9

rowScope.$on('ngGridEventStartCellEdit', function () {
targetRow.attr('draggable', 'false');
targetRow.off('dragstart', onDragStart);
});
rowScope.$on('ngGridEventEndCellEdit', function () {
targetRow.attr('draggable', 'true');
targetRow.on('dragstart', onDragStart);
});

###Bug 4: Can select some texts and then drag and drop it on the ng-gird
To fix this bug, it needs to remove dragover and drop event for the $viewport when editing

1
2
3
4
5
6
rowScope.$on('ngGridEventStartCellEdit', function () {
self.myGrid.$viewport.off('dragover', self.dragOver).off('drop', self.onRowDrop);
});
rowScope.$on('ngGridEventEndCellEdit', function () {
self.myGrid.$viewport.on('dragover', self.dragOver).on('drop', self.onRowDrop);
});

###The codes in gist