Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid-react does not render properly

Following the sample from the docs: https://www.ag-grid.com/best-react-data-grid/index.php

After creating new react app (have tried several times on different machines)

create-react-app whatever

If I apply the stylesheets (ag-grid.css & theme-fresh.css) all that is rendered is a gray line across the page. Any other combination renders a blank page. Removing ag-grid.css renders the grid but its jumbled all over the place.

Has anyone used this lately successfully with React? Does anyone recommend something different? (requirements: paging, sorting, filtering, selectable row(s))

thanks :-)

import React, { Component } from 'react';
import {AgGridReact} from 'ag-grid-react';
import '../node_modules/ag-grid/dist/styles/ag-grid.css';
import '../node_modules/ag-grid/dist/styles/theme-fresh.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      columnDefs: [
        {headerName: 'First Name', field: 'name' },
        {headerName: 'Last Name', field: 'lname'  }
      ],
      rowData: [
        { name: 'Dave', lname: 'Smith' },
        { name: 'Tommy', lname: 'Smith' },
        { name: 'Lea', lname: 'Jones' }
      ]
    }
  }
  render() {
    return (
      <div className="ag-fresh">
        <AgGridReact
            columnDefs={this.state.columnDefs}
            rowData={this.state.rowData}
          rowSelection="multiple"
          enableColResize="true"
          enableSorting="true"
          enableFilter="true"
          groupHeaders="true"
          rowHeight="22"
          debug="true"
        />
      </div>
    );
  }
}

export default App;
like image 694
schmoopy Avatar asked Sep 21 '16 05:09

schmoopy


People also ask

How do you make AG grid responsive in react JS?

The quickest way to achieve a responsive grid is to set the grid's containing div to a percentage. With this simple change the grid will automatically resize based on the div size and columns that can't fit in the viewport will simply be hidden and available to the right via the scrollbar.

How do you Rerender AG grid in react?

Refresh Cells: api. refreshCells(cellRefreshParams) - Gets the grid to refresh all cells. Change detection will be used to refresh only cells whose display cell values are out of sync with the actual value. If using a cellRenderer with a refresh method, the refresh method will get called.

What is deltaRowDataMode?

The deltaRowDataMode is designed to allow ag-Grid work with immutable stores such as Redux. In an immutable store, a new list of rowData is created if any row within it is added, removed or updated.

How do you update data on Ag grid react?

The easiest way to update data inside the grid is to replace the data you gave it with a fresh set of data. This is done by either updating the rowData bound property (if using a framework) or calling api. setRowData(newData) .


2 Answers

The outer grid required a height :-(

The documentation does not show this. Not sure why there is no min default height for the grid, but there is not.

like image 91
schmoopy Avatar answered Sep 19 '22 13:09

schmoopy


So essentially you need something like this, where the grid is wrapped with an element which has a height:

<div className="ag-fresh">
  <div className="grid_height_fix">
  <AgGridReact columnDefs={this.state.columnDefs} rowData={this.state.data.gridDate} >
  </AgGridReact>
  </div>
</div>
.grid_height_fix {height:800px;}
like image 26
Dave Avatar answered Sep 22 '22 13:09

Dave