2

I'm trying to render a very simple table with React and the Blueprint UI toolkit.

The documentation relative to the Table component is quite simple, but it seems like my code doesn't work.

import React from 'react';
import ReactDOM from 'react-dom';
import * as Blueprint from '@blueprintjs/core';
import { Cell, Column, Table } from '@blueprintjs/table';

const renderCell = (rowIndex: number) => {
    return <Cell>{`$${(rowIndex * 10).toFixed(2)}`}</Cell>
};

var myTable = (
  <Table numRows={10}>
    <Column name="Dollars" renderCell={renderCell}/>
  </Table>
);

ReactDOM.render(
  myTable,
  document.getElementById('myTable')
);

The image below shows what I get. How do I fix it?

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Luke
  • 2,976
  • 6
  • 34
  • 44

4 Answers4

8

Are you including blueprint.css and blueprint-table.css on your page? The Table won't render correctly without its stylesheets!

Gilad Gray
  • 451
  • 2
  • 6
  • I have the same problem, the suggested include is not working with a boiler plate that uses webpack, and require() won't include the css either due to the @ in the @blueprintjs module name, any ideas? – perrohunter Dec 11 '16 at 05:39
  • 3
    Interesting...this is not in the [table install docs](http://blueprintjs.com/docs/#table-js.installation). For me, the file was in `node_modules/@blueprintjs/table/dist/table.css` (notice the different css filename). – webelo Dec 20 '17 at 21:43
3

I had to include this line in my css file (using webpack setup by create-react-app):

@import '~@blueprintjs/table/dist/table.css';
3

For me,

yarn add @blueprintjs/core @blueprintjs/table

Then using a relative path from my react component file

import { Cell, Column, Table } from '@blueprintjs/table'

import '../../node_modules/@blueprintjs/table/lib/css/table.css'
ascripter
  • 5,665
  • 12
  • 45
  • 68
Ian
  • 31
  • 1
  • 2
-3

import '@blueprintjs/core/dist/blueprint.css'