簡體   English   中英

Ag-grid 樹數據功能未顯示數據

[英]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 });
                });
        }

    }

圖 1:瀏覽器中的 output 在此處輸入圖像描述

圖 2:上述 output 的控制台 在此處輸入圖像描述 圖 3:即使申請了 Ag-grid 提供的試用許可證 在此處輸入圖像描述

在就試用許可證聯系 Ag-grid 支持團隊后,他們建議我應該使用 px 而不是 % 來設置包含 Ag-grid 元素的 DIV 元素的高度和寬度。

出於某種原因,給出謹慎的值而不是百分比是可行的。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM