Your search did not match any results.
DataGrid

SignalR Service

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 CodePen
Apply
Reset
var DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', function DemoController($scope) { var store = new DevExpress.data.CustomStore({ load: function () { return connection.invoke("getAllStocks"); }, key: "symbol" }); $scope.dataGridOptions = { twoWayBindingEnabled: false, showBorders: true, repaintChangesOnly: true, highlightChanges: true, dataSource: { store: store }, columns: [{ dataField: "lastUpdate", dataType: "date", width: 115, format: "longTime" }, { dataField: "symbol" }, { dataField: "price", dataType: "number", format: "#0.####", cellTemplate: "priceCellTemplate" }, { dataField: "change", dataType: "number", width: 140, format: "#0.####", cellTemplate: "changeCellTemplate" }, { dataField: "dayOpen", dataType: "number", format: "#0.####" }, { dataField: "dayMin", dataType: "number", format: "#0.####" }, { dataField: "dayMax", dataType: "number", format: "#0.####" }], loadPanel: { enabled: false } }; $scope.connectionStarted = false; var connection = new signalR.HubConnectionBuilder() .withUrl("/Demos/NetCore/liveUpdateSignalRHub") .configureLogging(signalR.LogLevel.Information) .build(); connection.start() .then(function () { connection.on("updateStockPrice", function (data) { store.push([{ type: "update", key: data.symbol, data: data }]); }); $scope.connectionStarted = true; $scope.$apply(); }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <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/18.2.3/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/18.2.3/css/dx.light.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C\/script%3E'))</script> <script src="https://cdn3.devexpress.com/jslib/18.2.3/js/dx.all.js"></script> <script src="js/signalr/signalr-client.js"></script> <link rel="stylesheet" type ="text/css" href ="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div ng-if="connectionStarted"> <div id="gridContainer" dx-data-grid="dataGridOptions" dx-item-alias="cell"> <div data-options="dxTemplate:{ name:'priceCellTemplate' }" ng-class="{ inc: cell.data.change > 0, dec: cell.data.change < 0 }" class="ng-hide" ng-show="true"> <span>{{cell.text}}</span> </div> <div data-options="dxTemplate:{ name:'changeCellTemplate' }" ng-class="{ inc: cell.data.change > 0, dec: cell.data.change < 0 }" class="ng-hide" ng-show="true"> <span class='current-value'>{{cell.text}}</span> <span class="arrow"></span> <span class='diff'>{{cell.data.percentChange.toFixed(2)}}%</span> </div> </div> </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='); }