Hui’s blog

Today is not easy, tomorrow is more difficult, but the day after tomorrow will be wonderful.

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.

//set dataTransfer as it's required by firefox
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.

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.

//It should disable drag/drop feature when editing
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

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