Your search did not match any results.
Data Grid

SignalR Service

This example demonstrates real-time data update in a DataGrid bound to a SignalR service. Access to the service is configured in a CustomStore.

The CustomStore fetches the remote dataset at launch and keeps its local copy. Whenever the remote dataset changes, the server calls a client-side function that updates the local copy of the dataset (updateStockPrices in this demo). This function uses the store's push(changes) method.

For server-side configuration, refer to the ASP.NET MVC version of this demo.

For more information about integration with push services, refer to the following help topic: Integration with Push Services.

NOTE: Data used in this demo is for demonstration purposes only.

Copy to CodeSandBox
<template> <div v-if="connectionStarted"> <DxDataGrid id="gridContainer" :data-source="dataSource" :repaint-changes-only="true" :highlight-changes="true" :show-borders="true" > <DxColumn :width="115" data-field="lastUpdate" data-type="date" format="longTime" /> <DxColumn data-field="symbol" /> <DxColumn data-field="price" data-type="number" format="#0.####" cell-template="priceCellTemplate" /> <DxColumn :width="140" data-field="change" data-type="number" format="#0.####" cell-template="changeCellTemplate" /> <DxColumn data-field="dayOpen" data-type="number" format="#0.####" /> <DxColumn data-field="dayMin" data-type="number" format="#0.####" /> <DxColumn data-field="dayMax" data-type="number" format="#0.####" /> <template #priceCellTemplate="{ data: cellData }"> <PriceCell :cell-data="cellData"/> </template> <template #changeCellTemplate="{ data: cellData }"> <ChangeCell :cell-data="cellData"/> </template> </DxDataGrid> </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('') .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: > 0, dec: < 0 }"> <span class="current-value">{{ cellData.text }}</span> <span class="arrow"/> <span class="diff">{{ }}%</span> </div> </template> <script> export default { props: { cellData: { type: Object, default: () => {} } } }; </script>
<template> <div :class="{ inc: > 0, dec: < 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="" /> <link rel="stylesheet" type="text/css" href="" /> <script src=""></script> <script src=""></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', meta: { '*.vue': { loader: 'vue-loader' }, }, paths: { 'npm:': '' }, map: { 'vue': 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', '@aspnet/signalr': 'npm:@aspnet/signalr@1.0.0/dist/cjs/index.js', 'tslib': 'npm:tslib@1.6.1', 'devextreme': 'npm:devextreme@20.1', 'devextreme-vue': 'npm:devextreme-vue@20.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram@1.0.9', 'devexpress-gantt': 'npm:devexpress-gantt@1.0.7', 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, }, babelOptions: { sourceMaps: false, stage0: true } });