import React from 'react';
import DataGrid, {
Column
} from 'devextreme-react/data-grid';
import CustomStore from 'devextreme/data/custom_store';
import { HubConnectionBuilder } from '@aspnet/signalr';
import PriceCell from './PriceCell.js';
import ChangeCell from './ChangeCell.js';
class App extends React.Component {
constructor(props) {
super(props);
this.state = { connectionStarted: false, dataSource: null };
var hubConnection = new HubConnectionBuilder()
.withUrl('https://js.devexpress.com/Demos/NetCore/liveUpdateSignalRHub')
.build();
var store = new CustomStore({
load: () => hubConnection.invoke('getAllStocks'),
key: 'symbol'
});
hubConnection
.start()
.then(() => {
hubConnection.on('updateStockPrice', (data) => {
store.push([{ type: 'update', key: data.symbol, data: data }]);
});
this.setState({ connectionStarted: true, dataSource: store });
});
}
render() {
return (
<div>
{this.state.connectionStarted &&
(<DataGrid
id="gridContainer"
dataSource={this.state.dataSource}
showBorders={true}
repaintChangesOnly={true}
highlightChanges={true}
>
<Column dataField="lastUpdate" dataType="date" width={115} format="longTime" />
<Column dataField="symbol" />
<Column dataField="price" dataType="number" format="#0.####" cellRender={PriceCell} />
<Column dataField="change" dataType="number" width={140} format="#0.####" cellRender={ChangeCell} />
<Column dataField="dayOpen" dataType="number" format="#0.####" />
<Column dataField="dayMin" dataType="number" format="#0.####" />
<Column dataField="dayMax" dataType="number" format="#0.####" />
</DataGrid>)
}
</div>
);
}
}
export default App;
import React from 'react';
export default function ChangeCell(cell) {
return (
<div className={cell.data.change > 0 ? 'inc' : 'dec' }>
<span className="current-value">{cell.text}</span>
<span className="arrow"></span>
<span className="diff">{cell.data.percentChange.toFixed(2)}%</span>
</div>
);
}
import React from 'react';
export default function DiscountCell(cell) {
return (
<div className={cell.data.change > 0 ? 'inc' : 'dec' }>
<span>{cell.text}</span>
</div>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(
<App />,
document.getElementById('app')
);
<!DOCTYPE html>
<html>
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.common.css" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import('./index.js');
</script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
</body>
</html>
#gridContainer span.current-value {
display: inline-block;
margin-right: 5px;
}
#gridContainer span.diff {
width: 50px;
display: inline-block;
}
#gridContainer .inc {
color: #2ab71b;
}
#gridContainer .dec {
color: #f00;
}
#gridContainer .inc .arrow,
#gridContainer .dec .arrow {
display: inline-block;
height: 10px;
width: 10px;
background-repeat: no-repeat;
background-size: 10px 10px;
}
#gridContainer .inc .arrow {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADKSURBVHjaYtTaLs1ABEiG0nPRJa56PEHhsxBhmCUQT4OyrwHxcXyKmQgYJgHE64CYDYrXQcXIMhCbAcgWkGzgNKh38QUB0QamIUUErkhKI9ZAGyCeTERkTYaqxWsgKA2txhdG6GGsvUNGGpeBRMUiGhCFGsqGzUBQQJsxkA5AemaiG5hDIBIIgQSgK0FmMDACs549kN5FZLjhA7+A2A2U9YSAOBeLAk4gnoBDczoOcSFGPIUDPxB/wCHHiKtwYGKgMhg1cBAaCBBgAJTUIL3ToPZfAAAAAElFTkSuQmCC');
}
#gridContainer .dec .arrow {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADJSURBVHjaYvzPgBfgkhYA4o8QFahKmBioDEYNHIQGsgBxIBCLkqgvAYi/g1mMjMjir0EJzR6If/6HpChKMMgMe3DKBeIcKhiY8x/MYoDj+RQYNgdkGLqBbEB8kgzDToL1YjEQhKWB+BUJhj0H64Eahs1AELYhMpJ+gtUiGYbLQBBOI8LANLBaIg1kAAc0vkiAqSPBQFAkHcNi2DGoHMkGgrAENOCRI0ECRQ2JBoKwJTQCfkLZDPgMZPxPXN5NhtJzMSsJVBMAAgwAyWSY2svfmrwAAAAASUVORK5CYII=');
}
System.config({
transpiler: 'plugin-babel',
paths: {
'npm:': 'https://unpkg.com/'
},
defaultExtension: 'js',
map: {
'react': 'npm:react@16/umd/react.development.js',
'react-dom': 'npm:react-dom@16/umd/react-dom.development.js',
'prop-types': 'npm:prop-types/prop-types.js',
'devextreme': 'npm:devextreme@19.2',
'devextreme-react': 'npm:devextreme-react@19.2',
'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js',
'quill': 'npm:quill@1.3.7/dist/quill.js',
'devexpress-diagram': 'npm:devexpress-diagram',
'devexpress-gantt': 'npm:devexpress-gantt',
// SystemJS plugins
'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js',
'systemjs-babel-build':
'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js',
'tslib': 'npm:tslib@1.6.1',
'@aspnet/signalr': 'npm:@aspnet/signalr@1.0.0/dist/cjs/index.js',
},
packages: {
'devextreme': {
defaultExtension: 'js'
},
'devextreme-react': {
main: 'index.js'
}
},
babelOptions: {
sourceMaps: false,
stage0: true,
react: true
}
});