4

I am trying to make this work for two days now. I am trying to show Tree data in Ag-grid in ReactJS using this article : https://www.ag-grid.com/javascript-grid-server-side-model-tree-data/

Maybe I missed something from their documentation. Please someone help.

Obviously their Tree data is an enterprise feature and I referred to their server side model.

Expected functionality : Tree data feature with data from server. Two modes : one time fetching all data Or lazy loading for batch wise data

My JSON is as follows:

[{
    "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"
            }
         ]
      }]
}]

And Code:

    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>
            );
        }

EDIT: I have prepared a small test repository on Github dedicated to this issue and in this GridExampleGrouping.js is being rendered but not 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 });
                });
        }

    }

Pic 1 : The output in browser : enter image description here

Pic 2 : The console for above output: enter image description here Pic 3 : Even after applying a Trial license given by Ag-grid : enter image description here

Akshay Raut
  • 413
  • 5
  • 19
  • enterprise feature has enterprise support, so may be your question would get proper response on their site – Rikin Sep 26 '19 at 17:28
  • @Rikin Hi. My company is going to buy the license only after client's approval and for that I am working on a POC. I'll try and contact Ag-grid team to see if they can provide help in trial version. Still I am hoping if someone who might have used Tree data feature could help me here. – Akshay Raut Sep 27 '19 at 03:42
  • Can you create plunker link with your example? – Rikin Sep 27 '19 at 13:50
  • @Rikin Sorry for the late reply. I have prepared a git repo solely for this testing. https://github.com/HarvestAdmin/test-grid In this GridExampleGrouping.js is being rendered GridExampleTreeServer.js is not being rendered. – Akshay Raut Oct 06 '19 at 14:53
  • 1
    @Rikin I have added my answer with the help of ag-grid support team in case you were waiting for it. – Akshay Raut Oct 22 '19 at 11:58

1 Answers1

3

Upon contacting Ag-grid support team on Trial license, they recommended that I should use px instead of % to set height and width of the DIV element that contains Ag-grid element.

For some reason, giving discreet values rather than a percentage works.

enter image description here

Akshay Raut
  • 413
  • 5
  • 19
  • can you please answer this question: https://stackoverflow.com/questions/74410876/how-to-use-tree-data-in-ag-grid-v28 – Tanzeel Nov 12 '22 at 14:06