简体   繁体   English

无法将数据加载到Ag-Grid组件中

[英]Unable to load data in the ag-grid compoenent

     import React, { Component } from 'react';
        import {AgGridReact} from "ag-grid-react";
        import "ag-grid/dist/styles/ag-grid.css";
        import "ag-grid/dist/styles/theme-blue.css";
        export default class TableComponent extends Component {

        constructor(props) {
            super(props);
            this.state = {
            };
          }

          createHeader(){

              let columns = this.props.data.columns.map((col) => {
                      return {headerName:col.toUpperCase(),field:col}
                    });

              return columns; 
            }

             tableData(){

                    var res = this.props.data.columns;
                    var columns_name = res.map((col) => {
                                 return col
                               });
                    console.log(res);
                    console.log(columns_name);
                    var temp =[];
                    for(var i =1; i< res[0].length;i++){
                     var draft={};
                     for(var j =0; j< columns_name.length; j++){
                       draft[columns_name[j]] = '';
                     }

                     temp.push(draft);

                    }
                     console.log(temp);
                     for(var i =0; i< columns_name.length; i++){
                         for(var j =0; j<temp.length; j++){

                            temp[j][columns_name[i]] = res[i][j+1];

                         }

                     }


                      return temp;
                          }

          render() {
             return (
             <div style={containerStyle} className="ag-blue">
                    <AgGridReact
                        columnDefs={this.createHeader()}
                        rowData={this.tableData()}
                        enableFilter
                        enableSorting>
                    </AgGridReact>
                    </div>
           );
         }
        }

I am getting the table data in the following format. 我正在以以下格式获取表数据。

Response format From this format i am trying to load the data in the tabular format. 响应格式我正在尝试从这种格式以表格格式加载数据。 I can able to get the headers but the data is not populating. 我可以获取标题,但是数据没有填充。

I am getting the output in below 我在下面得到输出

output which i am getting . 我得到的输出

But how to get the proper data from the chart_data key from response which i am getting. 但是,如何从我得到的响应中,从chart_data键中获取正确的数据。

may i know what i am doing wrong here. 我可以知道我在这里做错了吗。

Just return chart_data because your response already in ag-grid row format. 只需返回chart_data即可,因为您的响应已采用ag-grid行格式。

tableData() { 
  return res.chart_data;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM