[英]Adding new row to ag-grid at the top of the grid react
I'm having trouble figuring out how i should properly go about adding a empty row to my ag-grid at the top of the table.我无法弄清楚我应该如何正确地向表格顶部的 ag-grid 添加一个空行。
Right now this is how my component / user lifecycle is:现在我的组件/用户生命周期是这样的:
Because the role I add is new, its 'id' is the highest, hence I believe it goes to the end of the table.因为我添加的角色是新的,它的 'id' 是最高的,因此我相信它会出现在表格的末尾。 However i could skip any reducer logic to add (step 9) and just manually do it like this:
但是,我可以跳过任何 reducer 逻辑来添加(第 9 步),只需手动执行如下操作:
this.props.api.addDispatcher({name: '', description: ''}).then((result) => {
this.props.api.updateRowData({ add: [result] });
});
Where the reducer does not have a case for 'ADD_ROLE', however this feels dirty.减速器没有“ADD_ROLE”的情况,但这感觉很脏。 I'm pretty stuck and don't believe this is the right path to take.
我很困惑,不相信这是正确的道路。 A general or better approach to take is very much appreciated.
非常感谢采用通用或更好的方法。
Even ontop of that i'm stuck on whether I should be utilizing redux to rehydrate my table or be depending on ag-grids api.甚至在此之上,我还纠结于是否应该使用 redux 来给我的桌子补充水分,还是依赖于 ag-grids api。 Ideally, I feel like using ag-grids api is more efficient.
理想情况下,我觉得使用 ag-grids api 更有效。
You can use the grid property of defaultGroupSortComparator
and provide a comparator of id it to make grid sorting.您可以使用
defaultGroupSortComparator
的 grid 属性并提供一个 id it 的比较器来进行网格排序。
// your comparator
const sortbyId(first, second) => {
// the logic;
}
render() {
return(
<AgGridReact
defaultGroupSortComparator={this.sortById}
/>);
}
您可以使用addIndex属性,所以在这种情况下
this.props.api.updateRowData({ add: [result], addIndex: 0 });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.