Your search did not match any results.
Data Grid

SignalR Service

Documentation

This example demonstrates real-time data update in the DataGrid widget bound to a SignalR server. Note that data used in this demo is for demonstration purposes only.

Copy to CodeSandBox
Apply
Reset
<template> <div v-if="connectionStarted"> <dx-data-grid id="gridContainer" :data-source="dataSource" :repaint-changes-only="true" :highlight-changes="true" :show-borders="true" > <dx-column :width="115" data-field="lastUpdate" data-type="date" format="longTime" /> <dx-column data-field="symbol" /> <dx-column data-field="price" data-type="number" format="#0.####" cell-template="priceCellTemplate" /> <dx-column :width="140" data-field="change" data-type="number" format="#0.####" cell-template="changeCellTemplate" /> <dx-column data-field="dayOpen" data-type="number" format="#0.####" /> <dx-column data-field="dayMin" data-type="number" format="#0.####" /> <dx-column data-field="dayMax" data-type="number" format="#0.####" /> <template #priceCellTemplate="{ data: cellData }"> <price-cell :cell-data="cellData"/> </template> <template #changeCellTemplate="{ data: cellData }"> <change-cell :cell-data="cellData"/> </template> </dx-data-grid> </div> </template> <script> import { DxDataGrid, DxColumn } from 'devextreme-vue/data-grid'; import CustomStore from 'devextreme/data/custom_store'; import { HubConnectionBuilder } from '@aspnet/signalr'; import PriceCell from './PriceCell.vue'; import ChangeCell from './ChangeCell.vue'; export default { components: { DxDataGrid, DxColumn, PriceCell, ChangeCell }, data() { return { connectionStarted: false, dataSource: null }; }, mounted() { 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.dataSource = store; this.connectionStarted = true; }); } }; </script> <style> #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='); } </style>
<template> <div :class="{ inc: cellData.data.change > 0, dec: cellData.data.change < 0 }"> <span class="current-value">{{ cellData.text }}</span> <span class="arrow"/> <span class="diff">{{ cellData.data.percentChange.toFixed(2) }}%</span> </div> </template> <script> export default { props: { cellData: { type: Object, default: () => {} } } }; </script>
<template> <div :class="{ inc: cellData.data.change > 0, dec: cellData.data.change < 0 }"> <span>{{ cellData.text }}</span> </div> </template> <script> export default { props: { cellData: { type: Object, default: () => {} } } }; </script>
import Vue from 'vue'; import App from './App.vue'; new Vue({ el: '#app', components: { App }, template: '<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" /> <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>
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, map: { vue: 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', 'devextreme': 'npm:devextreme@19.2', 'devextreme-vue': 'npm:devextreme-vue@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', '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' }, meta: { '*.vue': { loader: 'vue-loader' } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });