如何在Ag-Grid NG2(重新排序行)中拖动行



我需要在Ag-Grid-ng2中拖动行并重新排序行。我使用了ProcessRowPostCreate,但是事件(Ondragstart,Ondrop)并未被解雇。预先感谢您的任何帮助

我能够根据拖放弹力进行重新订立。这是我的代码。当用列对网格排序时,我跳过了修改(由于排序,拖放将没有任何视觉效果)。

        processRowPostCreate: (params) => {
            params.eRow.draggable = true;
            params.eRow.ondragstart = (event: DragEvent) => {
                this._newRowIndex = params.rowIndex;
                this._currentRowIndex = params.rowIndex;
            };
            params.eRow.ondragenter = (event: DragEvent) => {
                this._newRowIndex = params.rowIndex;
            };
            params.eRow.ondragend = (event: DragEvent) => {
                let sortmodel = this.gridOptions.api.getSortModel();
                if (sortmodel.length === 0 && this._newRowIndex !== this._currentRowIndex) {
                    let record = params.node.data;
                    this.handleRearrangement();
                    this.records.splice(this._newRowIndex, 0, this.records.splice(this._currentRowIndex, 1)[0]);
                    this.gridOptions.api.removeItems([params.node], false);
                    this.gridOptions.api.insertItemsAtIndex(this._newRowIndex, [record], false);
                } else {
                    this._newRowIndex = this._currentRowIndex; // just to be sure
                }
            };
        }

最新更新