请参考this plnkr。我使用了与之相同的基本思想,按字母顺序创建colDefs,然后在onGridReady函数中将列移动到各自的展示位置。有两个功能,这些功能在做这个有用,二是在我看来受欢迎得多:
moveColumn(colKey, toIndex)
//colKey refers to the id of the column which defaults to the specified field
//toIndex is simply a number that is within the range of columns.
moveColumns(colKeys[], toIndex)
//colKeys[] is an array in the order that you want them to be
displayed starting at the toIndex
下面是我在plnkr实现它:
private onReady() {
// this.gridOptions.columnApi.moveColumn('name',1)
// this.gridOptions.columnApi.moveColumn('country',2)
// this.gridOptions.columnApi.moveColumn('dob',3)
// this.gridOptions.columnApi.moveColumn('skills',4)
// this.gridOptions.columnApi.moveColumn('proficiency',5)
// this.gridOptions.columnApi.moveColumn('mobile',6)
// this.gridOptions.columnApi.moveColumn('landline',7)
// this.gridOptions.columnApi.moveColumn('address',8),
this.gridOptions.columnApi.moveColumns(['name', 'country', 'dob', 'skills', 'proficiency', 'mobile', 'landline', 'address'],1)
}
还有一个功能如果你想使用它:
moveColumnByIndex(fromIndex, toIndex)
//This uses just indexes and not the colid/colkey idea if you prefer
to keep it more anonymous
'moveColumn'正在为我工作,我正在使用v 7.0.2。如果你能向我们展示你的moveColumn的实现,我们可以从那里帮助你。 –
我发现问题出在ag-grid的版本上。 ** moveColumn **在** v6.4 **中不起作用。使用最新版本。 –