简体   繁体   English

将一行移动到顶部/底部或任何索引 ag-grid react

[英]Move a row to the top/bottom or at any index ag-grid react

I have been trying to move a particular row to the top of the grid, but unable to find any solution.我一直在尝试将特定行移动到网格的顶部,但找不到任何解决方案。 There is a default feature (Dragging row) available in the grid, which is not needed in this case.网格中有一个可用的默认功能(拖动行),在这种情况下不需要。 I have added a button using cell renderer and clicking to that button, the row should move to the top .我使用单元格渲染器添加了一个按钮并单击该按钮,该行应移至顶部

{
    headerName: "", field: "move",
    cellRenderer: (params) => {
        let eGui = document.createElement('div');
        let imageElement = document.createElement("img");
        imageElement.src = moveTopIcon;
        eGui.appendChild(imageElement);
        eGui.addEventListener('click', e => {
            //code to move the row
        });
        return eGui;
    }
}

Here is the column definition where button is placed.这是放置按钮的列定义。

I'm not sure whether AG-Grid has some hook to do that;我不确定 AG-Grid 是否有一些钩子可以做到这一点;

But you can achieve using the following approach:但是您可以使用以下方法实现:

On Click of button : Get the item you have clicked using event handler & Modify the row Data such that it's in top (index =0) .单击按钮时:使用事件处理程序获取您单击的项目并修改行数据,使其位于顶部 (index =0) 。 Let me know if this helps.如果这有帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM