[英]Ag-grid tree data feature is not showing data
我現在正在努力使這項工作兩天。 我正在嘗試使用這篇文章在 ReactJS 中的 Ag-grid 中顯示樹數據: https://www.ag-grid.com/javascript-grid-server-side-model-tree-data/
也許我從他們的文檔中遺漏了一些東西。 請有人幫忙。
顯然他們的樹數據是一個企業特性,我提到了他們的服務器端 model。
預期功能:帶有來自服務器的數據的樹數據功能。 兩種模式:一次獲取所有數據或延遲加載批量數據
我的 JSON 如下:
[{
"employeeId": 101,
"employeeName": "Erica Rogers",
"jobTitle": "CEO",
"employmentType": "Permanent",
"children": [{
"employeeId": 102,
"employeeName": "Malcolm Barrett",
"jobTitle": "Exec. Vice President",
"employmentType": "Permanent",
"children": [
{
"employeeId": 103,
"employeeName": "Leah Flowers",
"jobTitle": "Parts Technician",
"employmentType": "Contract"
},
{
"employeeId": 104,
"employeeName": "Tammy Sutton",
"jobTitle": "Service Technician",
"employmentType": "Contract"
}
]
}]
}]
和代碼:
import React, { Component } from 'react';
import { AgGridReact } from 'ag-grid-react';
import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-balham.css';
import 'ag-grid-enterprise';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{ field: "jobTitle" },
{ field: "employmentType" }
],
matchGridData: [],
autoGroupColumnDef: {
headerName: "Model",
field: "model",
cellRenderer: 'agGroupCellRenderer',
cellRendererParams: {
checkbox: true
}
},
// indicate if row is a group node
isServerSideGroup: function (dataItem) {
return dataItem.group;
},
// specify which group key to use
getServerSideGroupKey: function (dataItem) {
return dataItem.MatchGroup;
}
}
}
render() {
return (
<div
className="ag-theme-balham"
style={{
height: '500px',
width: '600px'
}}
>
<AgGridReact columnDefs={this.state.columnDefs} rowData={this.state.matchGridData} rowSelection="multiple"
onGridReady={params => this.gridApi = params.api} treeData={true} isServerSideGroup={this.state.isServerSideGroup}
getServerSideGroupKey={this.state.getServerSideGroupKey}
rowModelType='serverSide'
>
</AgGridReact>
</div>
);
}
編輯:我在 Github 上准備了一個小型測試存儲庫,專門用於此問題,在此 GridExampleGrouping.js 正在呈現但不是 GridExampleTreeServer.js: https://github.com/HarvestAdmin/test-grid
getMatchingData = e => {
fetch('/Matching/ResultGrid.aspx/GetMatchingData', {
method: 'POST',
body: JSON.stringify({ userId: this.state.userId, executionId: this.state.matchOrExecutionId, outputType: this.state.outputType, action: this.state.action }),
headers: {
"Content-Type": "application/json; charset=UTF-8",
"Accept": "application/json, text/javascript, */*; q=0.01",
"X-Requested-With": "XMLHttpRequest"
}
})
.then(response => {
return response.json();
}, error => {
return error.json();
})
.then(jsonResponse => {
var result = JSON.parse(jsonResponse.d);
console.log(result);
this.setState({ matchGridData: result.SearchResults.Table });
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.