Ag-Grid expand row

£可爱£侵袭症+ 提交于 2019-12-08 17:41:58

问题


Im using Ag-grid to control my table, but i want in my group that stores a list of rows instead of having to make the row group expand in 2 clicks, i want to be on 1 click. If i click on the icon arrow it works, but if i click on the title row it only opens on 2 clicks.

I already tried to find in the documentation any information about it, but cant find nothing.

Here is a example from the documentation. https://ag-grid.com/javascript-grid-tree/index.php

example image:


回答1:


You can listen to events on either a row or cell clicked, and expand nodes accordingly.

For example to expand a row based on a click you could do the following:

onRowClicked: (params) => {
    // update the node to be expanded
    params.node.expanded = true; 
    // tell the grid to redraw based on state of nodes expanded state 
    gridOptions.api.onGroupExpandedOrCollapsed(params.rowIndex)
}

This should be in the documentation - I'll update it to reflect this information.




回答2:


We are now recommended not to use the onGroupExpandedOrCollapsed, so this should now be...

This will also update the icons and animate the rows, which onGroupExpandedOrCollapsed won't.

onRowClicked(params) {
    params.node.setExpanded(!params.node.expanded);
}

This will toggle the expansion, use params.node.setExpanded(true) if you want the rows to just stay open.




回答3:


In the column definition, you can use the onCellClicked(params) function to tell it to do something when the cell is clicked. I tried looking for an expand function, but I could only find expandAll() which I don't think you will want. So what I would do is just use jquery or simple DOM selection to click on the expand icon inside of that cell.




回答4:


this one works

 onRowClicked(params) { 
    params.context.setExpand.onExpandClicked(params.rowIndex, params.node.rowHeight);
  }


来源:https://stackoverflow.com/questions/40083804/ag-grid-expand-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!