Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-virtualized table not rendering as a table

I have a super basic example that I wrote based on the demo, and it's not working:

import React from 'react';
import {
  Table,
  Column,
} from 'react-virtualized'

function MyTable(props) {
  return (
    <Table
      width={ 900 }
      height={ 500 }
      headerHeight={ 30 }
      rowHeight={ 30 }
      rowCount={ props.list.length }
      rowGetter={ ({ index }) => props.list[index] }
    >
      <Column
        width={ 250 }
        dataKey={ 'id' }
        headerRenderer={ ({ dataKey }) => 'Id' }
      />
      <Column
        width={ 250 }
        dataKey={ 'title' }
        headerRenderer={ ({ dataKey }) => 'Title' }
      />
    </Table>
  );
}

This is the result:

enter image description here

I'm sure I must be missing something, what am I missing, why is it not displaying as a table?

like image 276
Christopher Francisco Avatar asked Jan 28 '23 13:01

Christopher Francisco


1 Answers

You aren't importing CSS. The Table component is the only component that requires CSS to style the flexbox layout.

Check out the docs:

// Most of react-virtualized's styles are functional (eg position, size).
// Functional styles are applied directly to DOM elements.
// The Table component ships with a few presentational styles as well.
// They are optional, but if you want them you will need to also import the CSS file.
// This only needs to be done once; probably during your application's bootstrapping process.
import 'react-virtualized/styles.css'

// You can import any component you want as a named export from 'react-virtualized', eg
import { Column, Table } from 'react-virtualized'
like image 169
bvaughn Avatar answered Feb 16 '23 16:02

bvaughn