UNPKG

2.83 kBJavaScriptView Raw
1import React from 'react';
2import { render } from 'react-dom';
3import { HugeTable } from '../src';
4
5import schema from './schema';
6import data from './data';
7
8import '../src/HugeTable.less';
9import '../node_modules/bootstrap/less/bootstrap.less';
10
11function proxyImages (imageUrl) {
12 // Just return falsy image urls.
13 // If it already is served through https, there is no point in proxying.
14 if(!imageUrl || imageUrl.startsWith('https://')) {
15 return imageUrl;
16 }
17
18 return `https://images.weserv.nl/?url=${imageUrl.replace('http://', '')}`;
19}
20
21const mountNode = document.getElementById('main');
22
23const onSchemaChangeCallback = () => {
24 console.debug('Schema changed!', schema);
25};
26
27const options = {
28 height: 400,
29 width: 600,
30 mixedContentImage: proxyImages,
31 id: '1',
32};
33
34render(<HugeTable data={data.results} hideRowNumbers schema={schema} options={options} resizeByContent onSchemaChange={onSchemaChangeCallback} />, mountNode);
35
36// Rendereres example.
37
38const mountNode2 = document.getElementById('main2');
39const options2 = {
40 height: 800,
41 width: 1200,
42 mixedContentImage: proxyImages,
43 id: '2',
44};
45const renderers = {
46 HEADER(properties) {
47 // properties object might include following properties:
48 // `cellData` - REQUIRED - Object containing possible values of data that the cell can render.
49 // It should have at least the 'main' key but other values like `_text`,
50 // '_url' '_src' are possible. Those are dependant on the cell type.
51 // `width` - REQUIRED - The width that the cell will have. It is an informational value, can't be changed.
52 // The table is managing cell width and height because of column resizing ability.
53 // `height` - REQUIRED - Same as above, just for cell height.
54 // `columnKey` - REQUIRED - Name of th column key. Informational info.
55 // `key` - OPTIONAL - If a cell is rendered as part of array of values, it will have a custom key
56 // that should be rendered on the cell, to satisfy React's rendering of lists of data.
57 // `columnDataType` - OPTIONAL - Defines the type of column. The same as the the key in the `renderers` object.
58 // `mixedContentImage` - OPTIONAL - The same function that was passed to the `huge-table` props options.
59 //
60 return <div>H: {properties.cellData.main}</div>;
61 },
62};
63
64render(
65 <HugeTable data={data.results}
66 disableClickEvents
67 buttonColumnWidth={40}
68 rowHeight={30}
69 headerHeight={30}
70 showScrollingArrows
71 schema={schema}
72 options={options2}
73 renderers={renderers}
74 onSchemaChange={onSchemaChangeCallback}
75 resizeByContent
76 activeColumnIndex={6}
77 />, mountNode2);