ngx-datatable 详细信息行未扩展
ngx-datatable detail row not expanding
我正在尝试创建一个 ngx-datatable,我可以在任何地方重复使用它来保持样式和编辑等工作的方式。
大多数情况下一切正常,但我不明白为什么我无法正确展开详细信息行。
这是常见的 table 组件 html/template:
普通-table.component.html
<div>
<h3>Results</h3>
<ngx-datatable
#myTable
class="material expandable"
[rows]="data"
[columns]="columns"
[columnMode]="'force'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="'auto'"
[externalPaging]="hasServerPaging"
[count]="tablePaging.count"
[offset]="tablePaging.offset"
[limit]="tablePaging.limit"
(page)='setPage($event)'>
<ngx-datatable-row-detail *ngIf="hasDetails" [rowHeight]="rowDetailHeight" #myDetailRow [template]="rowDetails" (toggle)="onDetailToggle($event)">
</ngx-datatable-row-detail>
</ngx-datatable>
</div>
父组件包含要传递的列和模板引用的定义:
搜索-results.component.html
<ng-template #rowDropDownTemplate let-row="row" ngx-datatable-cell-template>
<a [class.datatable-icon-right]="!row.$$expanded" [class.datatable-icon-down]="!row.$$expanded" title="Expand/Collapse Details"
(click)="toggleExpandRow(row)">
</a>
</ng-template>
<ng-template #rowDetailsTemplate let-row="row" ngx-datatable-row-detail-template>
<div class="uk-grid">
<div class="uk-width-1-2">
left-side data
</div>
<div class="uk-width-1-2">
right-side data
</div>
</div>
</ng-template>
<app-common-table
*ngIf="results && results.length > 0"
[tablePaging]="tablePaging"
[columns]="columns"
[data]="tableData"
[rowDetails]="rowDetailsTemplate"
[rowDetailHeight]="200"
[hasServerPaging]="true"
(onPaging)="onPaging($event)"
></app-common-table>
针对代码中可能出现的问题,以下是列的设置方式:
搜索-results.component.ts
private setColumns(): void {
this._columns = [];
let templateTest: TemplateRef<any>;
let dropDownColumn: TableColumn = {
width: 50,
resizeable: false,
sortable: false,
draggable: false,
canAutoResize: false,
cellTemplate: this.rowDropDownTemplate,
}
this._columns.push(dropDownColumn);
let nameColumn: TableColumn = {
name: "Name",
width: 120
};
this._columns.push(nameColumn);
let positionsColumn: TableColumn = {
name: "Positions",
width: 200
};
this._columns.push(positionsColumn);
let experienceColumn: TableColumn = {
name: "Experience",
width: 80
};
this._columns.push(experienceColumn);
let leveleColumn: TableColumn = {
name: "Level",
width: 80
};
this._columns.push(leveleColumn);
let educationeColumn: TableColumn = {
name: "Education",
width: 80
};
this._columns.push(educationeColumn);
}
出现数据,展开详细信息行的图标也出现。事件触发并显示行数据,但未显示任何内容。
任何帮助将不胜感激!!
我怀疑你的toggleExpandRow
方法有误
我会这样做:
app.common-table.ts
export class AppCommonTableComponent {
@ViewChild('myTable') myTable: any;
parent.component.ts
@ViewChild(AppCommonTableComponent) commonTable: AppCommonTableComponent;
toggleExpandRow(row) {
console.log('Toggled Expand Row!', row);
this.commonTable.myTable.rowDetail.toggleExpandRow(row);
}
并且您应该修复您的 rowDropDownTemplate
模板。应该是
[class.datatable-icon-right]="!row.$$expanded" [class.datatable-icon-down]="row.$$expanded"
如果你想得到合适的类
此问题已在版本 16.0.3 中修复
参考 https://github.com/swimlane/ngx-datatable/blob/master/docs/changelog.md
我正在尝试创建一个 ngx-datatable,我可以在任何地方重复使用它来保持样式和编辑等工作的方式。
大多数情况下一切正常,但我不明白为什么我无法正确展开详细信息行。
这是常见的 table 组件 html/template:
普通-table.component.html
<div>
<h3>Results</h3>
<ngx-datatable
#myTable
class="material expandable"
[rows]="data"
[columns]="columns"
[columnMode]="'force'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="'auto'"
[externalPaging]="hasServerPaging"
[count]="tablePaging.count"
[offset]="tablePaging.offset"
[limit]="tablePaging.limit"
(page)='setPage($event)'>
<ngx-datatable-row-detail *ngIf="hasDetails" [rowHeight]="rowDetailHeight" #myDetailRow [template]="rowDetails" (toggle)="onDetailToggle($event)">
</ngx-datatable-row-detail>
</ngx-datatable>
</div>
父组件包含要传递的列和模板引用的定义:
搜索-results.component.html
<ng-template #rowDropDownTemplate let-row="row" ngx-datatable-cell-template>
<a [class.datatable-icon-right]="!row.$$expanded" [class.datatable-icon-down]="!row.$$expanded" title="Expand/Collapse Details"
(click)="toggleExpandRow(row)">
</a>
</ng-template>
<ng-template #rowDetailsTemplate let-row="row" ngx-datatable-row-detail-template>
<div class="uk-grid">
<div class="uk-width-1-2">
left-side data
</div>
<div class="uk-width-1-2">
right-side data
</div>
</div>
</ng-template>
<app-common-table
*ngIf="results && results.length > 0"
[tablePaging]="tablePaging"
[columns]="columns"
[data]="tableData"
[rowDetails]="rowDetailsTemplate"
[rowDetailHeight]="200"
[hasServerPaging]="true"
(onPaging)="onPaging($event)"
></app-common-table>
针对代码中可能出现的问题,以下是列的设置方式: 搜索-results.component.ts
private setColumns(): void {
this._columns = [];
let templateTest: TemplateRef<any>;
let dropDownColumn: TableColumn = {
width: 50,
resizeable: false,
sortable: false,
draggable: false,
canAutoResize: false,
cellTemplate: this.rowDropDownTemplate,
}
this._columns.push(dropDownColumn);
let nameColumn: TableColumn = {
name: "Name",
width: 120
};
this._columns.push(nameColumn);
let positionsColumn: TableColumn = {
name: "Positions",
width: 200
};
this._columns.push(positionsColumn);
let experienceColumn: TableColumn = {
name: "Experience",
width: 80
};
this._columns.push(experienceColumn);
let leveleColumn: TableColumn = {
name: "Level",
width: 80
};
this._columns.push(leveleColumn);
let educationeColumn: TableColumn = {
name: "Education",
width: 80
};
this._columns.push(educationeColumn);
}
出现数据,展开详细信息行的图标也出现。事件触发并显示行数据,但未显示任何内容。
任何帮助将不胜感激!!
我怀疑你的toggleExpandRow
方法有误
我会这样做:
app.common-table.ts
export class AppCommonTableComponent {
@ViewChild('myTable') myTable: any;
parent.component.ts
@ViewChild(AppCommonTableComponent) commonTable: AppCommonTableComponent;
toggleExpandRow(row) {
console.log('Toggled Expand Row!', row);
this.commonTable.myTable.rowDetail.toggleExpandRow(row);
}
并且您应该修复您的 rowDropDownTemplate
模板。应该是
[class.datatable-icon-right]="!row.$$expanded" [class.datatable-icon-down]="row.$$expanded"
如果你想得到合适的类
此问题已在版本 16.0.3 中修复 参考 https://github.com/swimlane/ngx-datatable/blob/master/docs/changelog.md