【问题标题】:How to Drag and drop rows within ag-grid ng2 (reorder rows)如何在 ag-grid ng2 中拖放行(重新排序行)
【发布时间】:2017-09-09 02:41:35
【问题描述】:

我需要在 ag-grid-ng2 中拖放行并重新排列行。我使用了 processRowPostCreate 但事件(ondragstart,ondrop)没有被触发。 在此先感谢您的帮助

【问题讨论】:

    标签: angular ag-grid-ng2


    【解决方案1】:

    我能够基于拖放功能进行重新排序。这是我的代码。当网格按列排序时,我跳过了修改(由于排序,拖放不会有任何视觉效果)。

            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
                    }
    
                };
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 2019-03-20
      • 2022-06-18
      • 2021-12-16
      • 2021-03-10
      • 2016-06-19
      • 2018-06-15
      相关资源
      最近更新 更多