|
| 1 | + |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | +import { Datagrid } from '@activewidgets/react'; |
| 5 | +import { northwind } from '@activewidgets/examples/data'; |
| 6 | +import * as templates from './templates'; |
| 7 | +import options from './options'; |
| 8 | +import './styles.css'; |
| 9 | + |
| 10 | + |
| 11 | +const columns = [ |
| 12 | + { header: 'Company', template: 'company', fixed: true }, |
| 13 | + { header: 'Contact', template: 'contact', style: 'background:#f4f4f4', key: 'contact' }, |
| 14 | + { header: 'Address', template: 'address', key: 'address' }, |
| 15 | + { header: 'Country', type: 'country flag', field: 'country' }, |
| 16 | + { header: 'Phone/Fax', type: 'phone & fax'}, |
| 17 | + { header: 'Last Order', type: 'money', field: 'amount' }, |
| 18 | + { header: 'Order Date', type: 'date', field: 'date' } |
| 19 | +]; |
| 20 | + |
| 21 | + |
| 22 | +const rows = northwind.customers; |
| 23 | + |
| 24 | + |
| 25 | +function onRow(row){ |
| 26 | + |
| 27 | + const {data, cells} = row; |
| 28 | + |
| 29 | + // calculated values |
| 30 | + cells.amount = 2000 * Math.random(); |
| 31 | + cells.date = Date.now() - 500 * 86400000 * Math.random(); |
| 32 | + |
| 33 | + |
| 34 | + // dynamic row style |
| 35 | + if (data.country == 'France'){ |
| 36 | + row.className = 'bg-green'; |
| 37 | + } |
| 38 | + |
| 39 | + // dynamic cell styles |
| 40 | + if (data.city == 'London'){ |
| 41 | + cells.address = {className: 'circle'}; |
| 42 | + } |
| 43 | + |
| 44 | + if (data.contactTitle == 'Owner'){ |
| 45 | + cells.contact = {className: 'star'}; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +function App(){ |
| 51 | + return <Datagrid columns={columns} rows={rows} templates={templates} options={options} onRow={onRow}/> |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +ReactDOM.render(<App />, document.getElementById('app')); |
0 commit comments