英文:
How to disable grouping in the Angular Grid if there is nothing to group?
问题
以下是代码的翻译部分:
@Component({
selector: 'my-app',
template:
`<ag-grid-angular
style="height: 100%;"
class="ag-theme-alpine"
[columnDefs]="columnDefs"
[animateRows]="true"
[rowData]="rowData"
(gridReady)="onGridReady($event)">
</ag-grid-angular>`,
})
export class AppComponent {
public columnDefs: ColDef[] = [
{ field: 'school', rowGroup: true, hide: true },
{ field: 'subject', rowGroup: true, hide: true },
{ field: 'branch' },
{ field: 'perfomance', aggFunc: 'avg' }
];
public rowData: any[];
onGridReady(params) {
this.rowData = [
{
school: 'SomeSchool',
subject: 'Music',
branch: undefined,
perfomance: 4
},
{
school: 'SomeSchool',
subject: 'Math',
branch: 'Algebra',
perfomance: 5
},
{
school: 'SomeSchool',
subject: 'Math',
branch: 'Geometry',
perfomance: 4.5
}
];
}
}
对于你的问题,如果你想要在"Music"这一行没有分组时禁用展开并仅显示它为"Music - Perfomance"一行,你可以考虑在数据中添加一个逻辑,检查是否有分支(branch)信息,如果没有,则在"subject"列中显示"Music - Perfomance",而不进行分组。这需要在数据准备阶段进行逻辑处理,具体实现可能需要根据你的应用程序逻辑来调整。
英文:
There is the following code:
@Component({
selector: 'my-app',
template:
`<ag-grid-angular
style="height: 100%;"
class="ag-theme-alpine"
[columnDefs]="columnDefs"
[animateRows]="true"
[rowData]="rowData"
(gridReady)="onGridReady($event)">
</ag-grid-angular>`,
})
export class AppComponent {
public columnDefs: ColDef[] = [
{ field: 'school', rowGroup: true, hide: true },
{ field: 'subject', rowGroup: true, hide: true },
{ field: 'branch' },
{ field: 'perfomance', aggFunc: 'avg' }
];
public rowData: any[];
onGridReady(params) {
this.rowData = [
{
school: 'SomeSchool',
subject: 'Music',
branch: undefined,
perfomance: 4
},
{
school: 'SomeSchool',
subject: 'Math',
branch: 'Algebra',
perfomance: 5
},
{
school: 'SomeSchool',
subject: 'Math',
branch: 'Geometry',
perfomance: 4.5
}
];
}
}
And such code is rendered to the grid so that if you open the Music item, it's just an empty string without branches, only with perfomance. And my question is, is there any way to make it so that if, as for Music, there is nothing to group, disable expanding for this row and show it only as Music - Perfomance in one row?
答案1
得分: 0
你查看过TreeData了吗?
https://www.ag-grid.com/angular-data-grid/tree-data/#file-browser-example
在示例中,temp.text文件与其他数据处于相同级别,但没有子项。然而,它仍然显示在其他列中的数据。
英文:
Have you looked into TreeData?
https://www.ag-grid.com/angular-data-grid/tree-data/#file-browser-example
See in the example the temp.text file is at the same level as the other data but has no children. However it still shows the data in other columns
答案2
得分: 0
根据文档,如果为autoGroupColumnDef
定义了cellRendererSelector
,则可以有条件地禁用单元格的分组。我已经这样设置,如果params.node.childrenMapped == null
,我们将使用默认的单元格渲染器。
英文:
According to the documentation, you can conditionally disable grouping for a cell if you define cellRendererSelector
for autoGroupColumnDef
. I made it so that we use the default cell renderer if params.node.childrenMapped == null
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论