首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ag-grid ng2中拖放行(重新排序行)

如何在ag-grid ng2中拖放行(重新排序行)
EN

Stack Overflow用户
提问于 2017-03-10 21:14:56
回答 1查看 916关注 0票数 0

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

EN

回答 1

Stack Overflow用户

发布于 2017-09-09 02:41:36

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

代码语言:javascript
复制
        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
                }

            };
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42719302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档