Dynamic Updates

FlexGrid updates all cells automatically when there are changes in its data source.

If you have a data source where only a few items change frequently, it is more efficient to update only the cells bound to items that have actually changed.

The grid below uses the formatItem event to keep track of the cell elements for each data item. When the data changes, it updates only the affected cells rather than the whole grid.




Name
Bid
Ask
Last Sale
Bid Size
Ask Size
Last Size
Volume
Quote Time
Quote Time
Royal Dutch Shell
370.86
0.0%
371.25
0.0%
370.86
0.0%
303
90
143
16,036
07:24:05
07:24:05
Unilever
273.02
0.0%
273.41
0.0%
273.02
0.0%
204
264
468
16,048
07:24:05
07:24:05
HSBC
264.37
0.0%
265.11
0.0%
264.37
0.0%
118
211
57
19,594
07:24:05
07:24:05
British American Tobacco
947.18
0.0%
947.70
0.0%
947.18
0.0%
429
23
230
10,127
07:24:05
07:24:05
GlaxoSmithKline
352.24
0.0%
352.63
0.0%
352.24
0.0%
428
495
359
14,372
07:24:05
07:24:05
SABMiller
272.09
0.0%
272.09
0.0%
272.09
0.0%
50
238
344
14,664
07:24:05
07:24:05
BP
664.98
0.0%
665.82
0.0%
664.98
0.0%
397
449
114
17,702
07:24:05
07:24:05
Vodafone Group
633.21
0.0%
633.34
0.0%
633.21
0.0%
114
345
54
17,027
07:24:05
07:24:05
AstraZeneca
310.30
0.0%
310.33
0.0%
310.30
0.0%
214
233
357
15,946
07:24:05
07:24:05
Reckitt Benckiser
256.57
0.0%
256.86
0.0%
256.57
0.0%
401
136
53
12,979
07:24:05
07:24:05
Diageo
806.43
0.0%
807.23
0.0%
806.43
0.0%
166
55
122
16,487
07:24:05
07:24:05
BT Group
772.56
0.0%
773.39
0.0%
772.56
0.0%
181
465
363
15,108
07:24:05
07:24:05
Lloyds Banking Group
469.24
0.0%
470.16
0.0%
469.24
0.0%
366
458
424
14,929
07:24:05
07:24:05
BHP Billiton
646.65
0.0%
647.23
0.0%
646.65
0.0%
500
296
81
14,615
07:24:05
07:24:05
National Grid plc
847.54
0.0%
847.57
0.0%
847.54
0.0%
454
160
471
17,471
07:24:05
07:24:05
Imperial Brands
877.49
0.0%
877.54
0.0%
877.49
0.0%
271
468
160
16,201
07:24:05
07:24:05
Rio Tinto Group
367.73
0.0%
368.34
0.0%
367.73
0.0%
42
122
262
16,744
07:24:05
07:24:05
Prudential plc
443.22
0.0%
443.28
0.0%
443.22
0.0%
413
288
82
17,616
07:24:05
07:24:05
Royal Bank of Scotland Group
748.82
0.0%
748.84
0.0%
748.82
0.0%
469
488
312
18,121
07:24:05
07:24:05
Barclays
952.44
0.0%
952.45
0.0%
952.44
0.0%
258
355
479
16,659
07:24:05
07:24:05
Associated British Foods
424.53
0.0%
425.44
0.0%
424.53
0.0%
397
286
462
12,699
07:24:05
07:24:05
RELX Group
811.81
0.0%
812.74
0.0%
811.81
0.0%
265
494
266
17,264
07:24:05
07:24:05
Rexam
778.55
0.0%
778.80
0.0%
778.55
0.0%
98
154
136
10,410
07:24:05
07:24:05
Carnival Corporation & plc
361.49
0.0%
361.98
0.0%
361.49
0.0%
186
399
309
11,649
07:24:05
07:24:05
Shire plc
362.44
0.0%
363.40
0.0%
362.44
0.0%
368
12
282
15,206
07:24:05
07:24:05
Compass Group
498.57
0.0%
499.41
0.0%
498.57
0.0%
385
265
206
19,722
07:24:05
07:24:05
WPP plc
190.72
0.0%
190.96
0.0%
190.72
0.0%
212
36
417
13,582
07:24:05
07:24:05
Aviva
808.80
0.0%
809.11
0.0%
808.80
0.0%
244
288
467
16,451
07:24:05
07:24:05
Sky plc
513.56
0.0%
514.45
0.0%
513.56
0.0%
325
45
336
14,093
07:24:05
07:24:05
Glencore
195.72
3.8%
198.58
5.3%
197.15
4.5%
563
973
768
13,045
07:24:05
07:24:05
BAE Systems
753.46
5.2%
696.49
-2.9%
724.98
1.2%
661
947
804
18,568
07:24:05
07:24:05
Tesco
730.33
0.0%
730.74
0.0%
730.33
0.0%
412
272
217
15,562
07:24:05
07:24:05
SSE plc
346.50
0.0%
346.69
0.0%
346.50
0.0%
485
89
29
10,012
07:24:05
07:24:05
Standard Chartered
836.61
0.0%
837.38
0.0%
836.61
0.0%
337
257
411
17,398
07:24:05
07:24:05
Legal & General
972.26
0.0%
973.19
0.0%
972.26
0.0%
344
12
439
13,013
07:24:05
07:24:05
ARM Holdings
693.64
0.0%
694.19
0.0%
693.64
0.0%
29
32
30
11,224
07:24:05
07:24:05
Rolls-Royce Holdings
970.86
0.0%
971.37
0.0%
970.86
0.0%
299
112
458
16,763
07:24:05
07:24:05
Experian
211.94
0.0%
212.82
0.0%
211.94
0.0%
186
316
441
16,012
07:24:05
07:24:05
International Consolidated Airlines Group SA
381.71
0.0%
382.62
0.0%
381.71
0.0%
143
395
131
11,171
07:24:05
07:24:05
CRH plc
499.74
5.3%
485.09
2.2%
492.42
3.7%
733
248
490
18,252
07:24:05
07:24:05
Centrica
354.68
0.0%
355.55
0.0%
354.68
0.0%
59
300
244
18,811
07:24:05
07:24:05
Smith & Nephew
599.53
0.0%
599.88
0.0%
599.53
0.0%
39
448
18
11,206
07:24:05
07:24:05
ITV plc
55.22
0.0%
56.10
0.0%
55.22
0.0%
345
262
456
10,711
07:24:05
07:24:05
Wolseley plc
531.36
0.0%
531.86
0.0%
531.36
0.0%
274
198
89
19,706
07:24:05
07:24:05
Old Mutual
22.17
0.0%
22.69
0.0%
22.17
0.0%
28
495
225
19,797
07:24:05
07:24:05
Land Securities
688.91
0.0%
689.14
0.0%
688.91
0.0%
51
297
200
13,692
07:24:05
07:24:05
London Stock Exchange Group
60.97
0.0%
61.42
0.0%
60.97
0.0%
219
110
101
10,480
07:24:05
07:24:05
Kingfisher plc
846.56
0.0%
847.18
0.0%
846.56
0.0%
109
62
79
16,707
07:24:05
07:24:05
Capita
830.12
0.0%
830.62
0.0%
830.12
0.0%
476
29
259
12,122
07:24:05
07:24:05
British Land
886.32
3.5%
861.17
0.6%
873.74
2.1%
887
556
721
13,059
07:24:05
07:24:05
Whitbread
770.76
0.0%
771.61
0.0%
770.76
0.0%
18
434
172
18,525
07:24:05
07:24:05
Marks & Spencer
922.80
1.2%
885.13
-2.9%
903.97
-0.8%
713
779
746
11,177
07:24:05
07:24:05
Fresnillo plc
831.97
0.0%
832.58
0.0%
831.97
0.0%
216
88
219
10,501
07:24:05
07:24:05
Next plc
744.69
0.0%
745.16
0.0%
744.69
0.0%
178
474
360
12,156
07:24:05
07:24:05
Schroders
992.60
0.0%
993.28
0.0%
992.60
0.0%
372
492
213
17,872
07:24:05
07:24:05
Standard Life
577.87
1.0%
572.57
0.0%
575.22
0.6%
133
276
204
10,606
07:24:05
07:24:05
Pearson PLC
144.58
0.0%
145.51
0.0%
144.58
0.0%
382
80
250
14,119
07:24:05
07:24:05
Bunzl
980.86
0.0%
981.37
0.0%
980.86
0.0%
373
237
135
16,848
07:24:05
07:24:05
Mondi
736.66
0.0%
736.99
0.0%
736.66
0.0%
108
169
387
10,561
07:24:05
07:24:05
United Utilities
79.94
0.0%
80.46
0.0%
79.94
0.0%
476
328
195
16,604
07:24:05
07:24:05
Persimmon plc
107.32
0.0%
107.83
0.0%
107.32
0.0%
387
262
103
17,268
07:24:05
07:24:05
Sage Group
6.81
0.0%
7.34
0.0%
6.81
0.0%
499
133
496
11,748
07:24:05
07:24:05
EasyJet
326.95
0.0%
327.73
0.0%
326.95
0.0%
281
265
90
15,990
07:24:05
07:24:05
Anglo American plc
898.82
0.0%
898.88
0.0%
898.82
0.0%
245
43
363
16,591
07:24:05
07:24:05
Taylor Wimpey
690.25
0.0%
690.68
0.0%
690.25
0.0%
326
358
142
14,003
07:24:05
07:24:05
TUI Group
224.71
0.0%
224.75
0.0%
224.71
0.0%
384
412
344
14,198
07:24:05
07:24:05
Worldpay
249.98
0.0%
250.93
0.0%
249.98
0.0%
197
478
308
16,451
07:24:05
07:24:05
Randgold Resources
673.15
4.5%
640.13
-0.7%
656.64
1.9%
602
866
734
15,409
07:24:05
07:24:05
Hargreaves Lansdown
573.70
0.0%
574.52
0.0%
573.70
0.0%
135
317
333
15,821
07:24:05
07:24:05
Barratt Developments
647.86
0.0%
648.55
0.0%
647.86
0.0%
146
465
428
18,000
07:24:05
07:24:05
InterContinental Hotels Group
854.10
0.0%
854.35
0.0%
854.10
0.0%
367
168
43
10,075
07:24:05
07:24:05
Burberry
689.02
0.0%
689.16
0.0%
689.02
0.0%
26
79
46
12,064
07:24:05
07:24:05
Dixons Carphone
979.03
0.0%
980.03
0.0%
979.03
0.0%
412
272
170
13,928
07:24:05
07:24:05
Direct Line Group
748.59
0.0%
749.00
0.0%
748.59
0.0%
440
88
454
12,816
07:24:05
07:24:05
Coca-Cola HBC AG
814.22
0.0%
814.88
0.0%
814.22
0.0%
190
68
319
10,427
07:24:05
07:24:05
Severn Trent
330.91
0.0%
331.45
0.0%
330.91
0.0%
357
411
368
15,097
07:24:05
07:24:05
DCC plc
491.61
0.0%
492.26
0.0%
491.61
0.0%
173
24
430
16,421
07:24:05
07:24:05
Sainsbury's
198.86
0.0%
199.40
0.0%
198.86
0.0%
434
481
92
18,541
07:24:05
07:24:05
Admiral Group
77.27
-1.8%
79.31
0.3%
78.29
-0.8%
24
98
61
17,616
07:24:05
07:24:05
GKN
909.61
0.0%
910.49
0.0%
909.61
0.0%
53
447
399
19,433
07:24:05
07:24:05
Johnson Matthey
314.88
0.0%
315.35
0.0%
314.88
0.0%
314
374
286
13,485
07:24:05
07:24:05
Provident Financial
363.99
0.0%
364.63
0.0%
363.99
0.0%
75
475
241
16,155
07:24:05
07:24:05
Antofagasta
145.54
0.0%
145.66
0.0%
145.54
0.0%
381
340
374
17,997
07:24:05
07:24:05
St. James's Place plc
890.73
-3.4%
901.64
-2.3%
896.18
-2.8%
315
988
651
11,420
07:24:05
07:24:05
Intertek
137.31
0.0%
138.13
0.0%
137.31
0.0%
293
239
342
15,483
07:24:05
07:24:05
Babcock International
550.99
0.0%
551.43
0.0%
550.99
0.0%
467
86
341
16,123
07:24:05
07:24:05
Berkeley Group Holdings
38.63
0.0%
39.10
0.0%
38.63
0.0%
408
110
304
10,216
07:24:05
07:24:05
Inmarsat
521.68
0.0%
522.03
0.0%
521.68
0.0%
320
327
388
12,893
07:24:05
07:24:05
Travis Perkins
699.27
0.0%
699.39
0.0%
699.27
0.0%
282
386
296
17,774
07:24:05
07:24:05
Hammerson
327.41
0.0%
328.25
0.0%
327.41
0.0%
471
88
351
16,407
07:24:05
07:24:05
Merlin Entertainments
65.32
0.0%
65.74
0.0%
65.32
0.0%
286
285
75
16,918
07:24:05
07:24:05
Royal Mail
629.28
0.0%
629.84
0.0%
629.28
0.0%
214
482
180
13,660
07:24:05
07:24:05
Ashtead Group
208.49
0.0%
208.84
0.0%
208.49
0.0%
445
110
364
14,707
07:24:05
07:24:05
RSA Insurance Group
193.54
0.0%
194.27
0.0%
193.54
0.0%
270
35
160
12,853
07:24:05
07:24:05
3i
133.35
0.0%
133.44
0.0%
133.35
0.0%
432
465
415
14,440
07:24:05
07:24:05
Intu Properties
599.01
0.0%
599.63
0.0%
599.01
0.0%
325
376
146
14,287
07:24:05
07:24:05
Smiths Group
389.40
0.0%
390.33
0.0%
389.40
0.0%
261
480
486
18,257
07:24:05
07:24:05
Hikma Pharmaceuticals
820.36
0.0%
820.72
0.0%
820.36
0.0%
62
445
332
17,067
07:24:05
07:24:05
Aberdeen Asset Management
530.52
0.0%
530.60
0.0%
530.52
0.0%
266
169
81
12,015
07:24:05
07:24:05
Sports Direct
471.99
0.0%
472.15
0.0%
471.99
0.0%
486
338
465
16,592
07:24:05
07:24:05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// This file locates: "Scripts/Lesson/C1FlexGrid/DynamicUpdates.js".
c1.documentReady(function () {
    var theGrid = wijmo.Control.getControl('#theGrid');
    theGrid.itemsSource = data;
 
    // control panel
    var customCells = true;
    var autoUpdate = true;
    var interval = 100; // update interval in ms: 1000, 500, 100, 10, 1
    var batchSize = 5; // items to update: 100, 50, 10, 5, 1
 
    document.getElementById('customCells').addEventListener('click', function (e) {
        customCells = e.target.checked;
        theGrid.invalidate();
    });
    document.getElementById('autoUpdate').addEventListener('click', function (e) {
        autoUpdate = e.target.checked;
        theGrid.invalidate();
    });
 
    var cmbInterval = wijmo.Control.getControl('#updateInterval');
    cmbInterval.selectedIndexChanged.addHandler(function (s, e) {
        interval = cmbInterval.selectedValue;
    });
 
    var cmbBatchSize = wijmo.Control.getControl('#batchSize');
    cmbBatchSize.selectedIndexChanged.addHandler(function (s, e) {
        batchSize = cmbBatchSize.selectedValue;
    });
 
    theGrid.rowHeaders.columns[0].width = 80;
 
    // cellElements object keeps track of grid's cell elements
    var clearCells = false;
    var cellElements = {};
    theGrid.updatingView.addHandler(function (s, e) {
        clearCells = true; // clear cell elements on next formatItem
    });
 
    // formatItem hander displays cells and keeps track of cell elements
    theGrid.formatItem.addHandler(function (s, e) {
 
        // show symbols in row headers
        if (e.panel == s.rowHeaders && e.col == 0) {
            e.cell.textContent = item = s.rows[e.row].dataItem.symbol;
        }
 
        // regular cells
        if (e.panel == s.cells) {
            var col = s.columns[e.col],
                item = s.rows[e.row].dataItem;
 
            // clear cell elements
            if (clearCells) {
                clearCells = false;
                cellElements = {};
            }
 
            // store cell element
            if (!cellElements[item.symbol]) {
                cellElements[item.symbol] = { item: item };
            }
            cellElements[item.symbol][col.binding] = e.cell;
 
            // custom painting
            formatCell(e.cell, item, col, false);
        }
    });
 
    // custom cell painting
    function formatCell(cell, item, col, flare) {
        if (customCells) {
            switch (col.binding) {
                case 'bid':
                    formatDynamicCell(cell, item, col, 'bidHistory', flare);
                    break;
                case 'ask':
                    formatDynamicCell(cell, item, col, 'askHistory', flare);
                    break;
                case 'lastSale':
                    formatDynamicCell(cell, item, col, 'saleHistory', flare);
                    break;
                default:
                    cell.textContent = wijmo.Globalize.format(item[col.binding], col.format);
                    break;
            }
        } else {
            cell.textContent = wijmo.Globalize.format(item[col.binding], col.format);
        }
    }
    function formatDynamicCell(cell, item, col, history, flare) {
 
        // cell template
        var html = '<div class="ticker chg-{dir} flare-{fdir}"> ' +
                '<div class="value">{value}</div >' +
                '<div class="chg">{chg}</div>' +
                '<div class="glyph"><span class="wj-glyph-{glyph}"></span></div>' +
                '<div class="spark">{spark}</div>' +
            '</div>';
 
        // value
        html = html.replace('{value}', wijmo.Globalize.format(item[col.binding], col.format));
 
        // % change
        var hist = item[history];
        var chg = hist.length > 1 ? hist[hist.length - 1] / hist[hist.length - 2] - 1 : 0;
        html = html.replace('{chg}', wijmo.Globalize.format(chg * 100, 'n1') + '%');
 
        // up/down glyph
        var glyph = chg > +0.001 ? 'up' : chg < -0.001 ? 'down' : 'circle';
        html = html.replace('{glyph}', glyph);
 
        // sparklines
        html = html.replace('{spark}', getSparklines(item[history]));
 
        // change direction
        var dir = glyph == 'circle' ? 'none' : glyph;
        html = html.replace('{dir}', dir);
 
        // flare direction
        var flareDir = flare ? dir : 'none';
        html = html.replace('{fdir}', flareDir);
 
        // done
        cell.innerHTML = html;
    }
 
    // update grid cells when items change
    function updateGrid(changedItems) {
        for (var symbol in changedItems) {
            var itemCells = cellElements[symbol];
            if (itemCells) {
                var item = itemCells.item;
                theGrid.columns.forEach(function (col) {
                    var cell = itemCells[col.binding];
                    if (cell) {
                        formatCell(cell, item, col, true);
                    }
                })
            }
        }
    }
 
    // simulate updates/notifications
    updateTrades();
    function updateTrades() {
        var now = new Date();
        var changedItems = {};
        for (var i = 0; i < batchSize; i++) {
 
            // select an item
            var item = data[randBetween(0, data.length - 1)];
 
            // update current data
            item.bid = item.bid * (1 + (Math.random() * .11 - .05));
            item.ask = item.ask * (1 + (Math.random() * .11 - .05));
            item.bidSize = randBetween(10, 1000);
            item.askSize = randBetween(10, 1000);
            var sale = (item.ask + item.bid) / 2;
            item.lastSale = sale;
            item.lastSize = Math.floor((item.askSize + item.bidSize) / 2);
            item.quoteTime = now;
            item.tradeTime = new Date(Date.now() + randBetween(0, 60000));
 
            // update history data
            addHistory(item.askHistory, item.ask);
            addHistory(item.bidHistory, item.bid);
            addHistory(item.saleHistory, item.lastSale);
 
            // keep track of changed items
            changedItems[item.symbol] = true;
        }
 
        // update the grid
        if (autoUpdate) {
            updateGrid(changedItems);
        }
 
        // and schedule the next batch
        setTimeout(updateTrades, interval);
    }
});
 
// add a value to a history array
function addHistory(array, data) {
    array.push(data);
    if (array.length > 10) { // limit history length
        array.splice(0, 1);
    }
}
 
// Companies in the Financial Times Stock Exchange 100 Index
// mcap: market capitalization (in billion pounds)
// emp: employees (thousands)
var companies = [
    { symbol: 'RDSA', name: 'Royal Dutch Shell', sector: 'Oil and gas', mcap: 160.12, emp: 90 },
    { symbol: 'ULVR', name: 'Unilever', sector: 'Consumer goods', mcap: 90.42, emp: 171 },
    { symbol: 'HSBA', name: 'HSBC', sector: 'Banking', mcap: 88.11, emp: 267 },
    { symbol: 'BATS', name: 'British American Tobacco', sector: 'Tobacco', mcap: 71.4, emp: 87 },
    { symbol: 'GSK', name: 'GlaxoSmithKline', sector: 'Pharmaceuticals', mcap: 67.38, emp: 97 },
    { symbol: 'SAB', name: 'SABMiller', sector: 'Beverages', mcap: 67.32, emp: 70 },
    { symbol: 'BP', name: 'BP', sector: 'Oil and gas', mcap: 63.13, emp: 97 },
    { symbol: 'VOD', name: 'Vodafone Group', sector: 'Telecomms', mcap: 56.55, emp: 86 },
    { symbol: 'AZN', name: 'AstraZeneca', sector: 'Pharmaceuticals', mcap: 51.23, emp: 57 },
    { symbol: 'RB', name: 'Reckitt Benckiser', sector: 'Consumer goods', mcap: 46.32, emp: 32 },
    { symbol: 'DGE', name: 'Diageo', sector: 'Beverages', mcap: 46.01, emp: 25 },
    { symbol: 'BT.A', name: 'BT Group', sector: 'Telecomms', mcap: 45.61, emp: 89 },
    { symbol: 'LLOY', name: 'Lloyds Banking Group', sector: 'Banking', mcap: 44.11, emp: 120 },
    { symbol: 'BLT', name: 'BHP Billiton', sector: 'Mining', mcap: 41.88, emp: 46 },
    { symbol: 'NG', name: 'National Grid plc', sector: 'Energy', mcap: 36.14, emp: 27 },
    { symbol: 'IMB', name: 'Imperial Brands', sector: 'Tobacco', mcap: 35.78, emp: 38 },
    { symbol: 'RIO', name: 'Rio Tinto Group', sector: 'Mining', mcap: 34.84, emp: 67 },
    { symbol: 'PRU', name: 'Prudential plc', sector: 'Finance', mcap: 31.63, emp: 25 },
    { symbol: 'RBS', name: 'Royal Bank of Scotland Group', sector: 'Banking', mcap: 28.6, emp: 150 },
    { symbol: 'BARC', name: 'Barclays', sector: 'Banking', mcap: 27.18, emp: 150 },
    { symbol: 'ABF', name: 'Associated British Foods', sector: 'Food', mcap: 25.77, emp: 102 },
    { symbol: 'REL', name: 'RELX Group', sector: 'Publishing', mcap: 25.54, emp: 28 },
    { symbol: 'REX', name: 'Rexam', sector: 'Packaging', mcap: 25.54, emp: 19 },
    { symbol: 'CCL', name: 'Carnival Corporation & plc', sector: 'Leisure', mcap: 24.85, emp: 86 },
    { symbol: 'SHP', name: 'Shire plc', sector: 'Pharmaceuticals', mcap: 22.52, emp: 4 },
    { symbol: 'CPG', name: 'Compass Group', sector: 'Food', mcap: 20.21, emp: 471 },
    { symbol: 'WPP', name: 'WPP plc', sector: 'Media', mcap: 19.01, emp: 162 },
    { symbol: 'AV.', name: 'Aviva', sector: 'Insurance', mcap: 17.69, emp: 40 },
    { symbol: 'SKY', name: 'Sky plc', sector: 'Media', mcap: 17.5, emp: 22 },
    { symbol: 'GLEN', name: 'Glencore', sector: 'Mining', mcap: 16.96, emp: 57 },
    { symbol: 'BA.', name: 'BAE Systems', sector: 'Military', mcap: 16.01, emp: 107 },
    { symbol: 'TSCO', name: 'Tesco', sector: 'Supermarket', mcap: 14.92, emp: 519 },
    { symbol: 'SSE', name: 'SSE plc', sector: 'Energy', mcap: 14.03, emp: 19 },
    { symbol: 'STAN', name: 'Standard Chartered', sector: 'Banking', mcap: 13.52, emp: 86 },
    { symbol: 'LGEN', name: 'Legal & General', sector: 'Insurance', mcap: 13.21, emp: 9 },
    { symbol: 'ARM', name: 'ARM Holdings', sector: 'Engineering', mcap: 13.2, emp: 2 },
    { symbol: 'RR.', name: 'Rolls-Royce Holdings', sector: 'Manufacturing', mcap: 11.8, emp: 55 },
    { symbol: 'EXPN', name: 'Experian', sector: 'Information', mcap: 11.1, emp: 17 },
    { symbol: 'IAG', name: 'International Consolidated Airlines Group SA', sector: 'Travel', mcap: 11.01, emp: 58 },
    { symbol: 'CRH', name: 'CRH plc', sector: 'Building materials', mcap: 10.9, emp: 76 },
    { symbol: 'CNA', name: 'Centrica', sector: 'Energy', mcap: 10.72, emp: 40 },
    { symbol: 'SN.', name: 'Smith & Nephew', sector: 'Medical', mcap: 10.27, emp: 11 },
    { symbol: 'ITV', name: 'ITV plc', sector: 'Media', mcap: 10.15, emp: 4 },
    { symbol: 'WOS', name: 'Wolseley plc', sector: 'Building materials', mcap: 9.2, emp: 44 },
    { symbol: 'OML', name: 'Old Mutual', sector: 'Insurance', mcap: 8.45, emp: 54 },
    { symbol: 'LAND', name: 'Land Securities', sector: 'Property', mcap: 8.19, emp: 0 },
    { symbol: 'LSE', name: 'London Stock Exchange Group', sector: 'Finance', mcap: 8.06, emp: 4 },
    { symbol: 'KGF', name: 'Kingfisher plc', sector: 'Retail homeware', mcap: 7.8, emp: 80 },
    { symbol: 'CPI', name: 'Capita', sector: 'Support Services', mcap: 7.38, emp: 46 },
    { symbol: 'BLND', name: 'British Land', sector: 'Property', mcap: 7.13, emp: 0 },
    { symbol: 'WTB', name: 'Whitbread', sector: 'Retail hospitality', mcap: 7.09, emp: 86 },
    { symbol: 'MKS', name: 'Marks & Spencer', sector: 'Retailer', mcap: 7.01, emp: 81 },
    { symbol: 'FRES', name: 'Fresnillo plc', sector: 'Mining', mcap: 6.99, emp: 2 },
    { symbol: 'NXT', name: 'Next plc', sector: 'Retail clothing', mcap: 6.9, emp: 58 },
    { symbol: 'SDR', name: 'Schroders', sector: 'Fund management', mcap: 6.63, emp: 3 },
    { symbol: 'SL', name: 'Standard Life', sector: 'Fund management', mcap: 6.63, emp: 10 },
    { symbol: 'PSON', name: 'Pearson PLC', sector: 'Education', mcap: 6.52, emp: 37 },
    { symbol: 'BNZL', name: 'Bunzl', sector: 'Industrial products', mcap: 6.38, emp: 12 },
    { symbol: 'MNDI', name: 'Mondi', sector: 'Manufacturing', mcap: 6.37, emp: 26 },
    { symbol: 'UU', name: 'United Utilities', sector: 'Water', mcap: 6.36, emp: 5 },
    { symbol: 'PSN', name: 'Persimmon plc', sector: 'Building', mcap: 6.34, emp: 2 },
    { symbol: 'SGE', name: 'Sage Group', sector: 'IT', mcap: 6.26, emp: 12 },
    { symbol: 'EZJ', name: 'EasyJet', sector: 'Travel', mcap: 6.17, emp: 11 },
    { symbol: 'AAL', name: 'Anglo American plc', sector: 'Mining', mcap: 6.09, emp: 100 },
    { symbol: 'TW.', name: 'Taylor Wimpey', sector: 'Building', mcap: 5.99, emp: 3 },
    { symbol: 'TUI', name: 'TUI Group', sector: 'Leisure', mcap: 5.99, emp: 76 },
    { symbol: 'WPG', name: 'Worldpay', sector: 'Payment services', mcap: 5.9, emp: 4 },
    { symbol: 'RRS', name: 'Randgold Resources', sector: 'Mining', mcap: 5.89, emp: 6 },
    { symbol: 'HL', name: 'Hargreaves Lansdown', sector: 'Finance', mcap: 5.87, emp: 0 },
    { symbol: 'BDEV', name: 'Barratt Developments', sector: 'Building', mcap: 5.86, emp: 5 },
    { symbol: 'IHG', name: 'InterContinental Hotels Group', sector: 'Hotels', mcap: 5.75, emp: 345 },
    { symbol: 'BRBY', name: 'Burberry', sector: 'Fashion', mcap: 5.65, emp: 10 },
    { symbol: 'DC.', name: 'Dixons Carphone', sector: 'Retail', mcap: 5.16, emp: 40 },
    { symbol: 'DLG', name: 'Direct Line Group', sector: 'Insurance', mcap: 5.15, emp: 13 },
    { symbol: 'CCH', name: 'Coca-Cola HBC AG', sector: 'Consumer', mcap: 5.1, emp: 38 },
    { symbol: 'SVT', name: 'Severn Trent', sector: 'Water', mcap: 5.04, emp: 8 },
    { symbol: 'DCC', name: 'DCC plc', sector: 'Investments', mcap: 5.03, emp: 9 },
    { symbol: 'SBRY', name: 'Sainsbury\'s', sector: 'Supermarket', mcap: 5.02, emp: 150 },
    { symbol: 'ADM', name: 'Admiral Group', sector: 'Insurance', mcap: 4.91, emp: 2 },
    { symbol: 'GKN', name: 'GKN', sector: 'Manufacturing', mcap: 4.79, emp: 50 },
    { symbol: 'JMAT', name: 'Johnson Matthey', sector: 'Chemicals', mcap: 4.79, emp: 9 },
    { symbol: 'PFG', name: 'Provident Financial', sector: 'Finance', mcap: 4.74, emp: 3 },
    { symbol: 'ANTO', name: 'Antofagasta', sector: 'Mining', mcap: 4.71, emp: 4 },
    { symbol: 'STJ', name: 'St. James\'s Place plc', sector: 'Finance', mcap: 4.68, emp: 1 },
    { symbol: 'ITRK', name: 'Intertek', sector: 'Product testing', mcap: 4.67, emp: 33 },
    { symbol: 'BAB', name: 'Babcock International', sector: 'Engineering', mcap: 4.65, emp: 34 },
    { symbol: 'BKG', name: 'Berkeley Group Holdings', sector: 'Building', mcap: 4.6, emp: 2 },
    { symbol: 'ISAT', name: 'Inmarsat', sector: 'Telecomms', mcap: 4.47, emp: 1 },
    { symbol: 'TPK', name: 'Travis Perkins', sector: 'Retailer', mcap: 4.46, emp: 24 },
    { symbol: 'HMSO', name: 'Hammerson', sector: 'Property', mcap: 4.42, emp: 0 },
    { symbol: 'MERL', name: 'Merlin Entertainments', sector: 'Leisure', mcap: 4.42, emp: 28 },
    { symbol: 'RMG', name: 'Royal Mail', sector: 'Delivery', mcap: 4.41, emp: 150 },
    { symbol: 'AHT', name: 'Ashtead Group', sector: 'Equipment rental', mcap: 4.26, emp: 12 },
    { symbol: 'RSA', name: 'RSA Insurance Group', sector: 'Insurance', mcap: 4.16, emp: 21 },
    { symbol: 'III', name: '3i', sector: 'Private equity', mcap: 4.06, emp: 0 },
    { symbol: 'INTU', name: 'Intu Properties', sector: 'Property', mcap: 3.89, emp: 2 },
    { symbol: 'SMIN', name: 'Smiths Group', sector: 'Engineering', mcap: 3.84, emp: 23 },
    { symbol: 'HIK', name: 'Hikma Pharmaceuticals', sector: 'Manufacturing', mcap: 3.71, emp: 6 },
    { symbol: 'ADN', name: 'Aberdeen Asset Management', sector: 'Fund management', mcap: 3.14, emp: 1 },
    { symbol: 'SPD', name: 'Sports Direct', sector: 'Retail', mcap: 2.4, emp: 17 }
];
 
// Trading Market Data
var data = [],
    now = new Date();
companies.forEach(function (company) {
    var bid = randBetween(1, 100000) / 100,
        ask = bid + randBetween(0, 100) / 100;
    data.push({
        symbol: company.symbol,
        name: company.name,
        bid: bid,
        ask: ask,
        lastSale: bid,
        bidSize: randBetween(10, 500),
        askSize: randBetween(10, 500),
        lastSize: randBetween(10, 500),
        volume: randBetween(10000, 20000),
        quoteTime: now,
        tradeTime: now,
        askHistory: [ask, ask],
        bidHistory: [bid, bid],
        saleHistory: [bid, bid]
    });
});
 
// get a random number within a given interval
function randBetween(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
}
 
// generate sparklines as SVG
function getSparklines(data) {
    var svg = '',
        min = Math.min.apply(Math, data),
        max = Math.max.apply(Math, data),
        x1 = 0,
        y1 = scaleY(data[0], min, max);
    for (var i = 1; i < data.length; i++) {
        var x2 = Math.round((i) / (data.length - 1) * 100);
        var y2 = scaleY(data[i], min, max);
        svg += '<line x1=' + x1 + '% y1=' + y1 + '% x2=' + x2 + '% y2=' + y2 + '% />';
        x1 = x2;
        y1 = y2;
    }
    return '<svg><g>' + svg + '</g></svg>';
}
function scaleY(value, min, max) {
    return max > min
    ? 100 - Math.round((value - min) / (max - min) * 100)
  : 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// This file locates: "Content/css/Lesson/C1FlexGrid/DynamicUpdates.css".
.wj-flexgrid {
    max-height: 500px;
}
.wj-flexgrid .wj-cell {
    padding: 6px;
}
.wj-flexgrid .wj-cell:not(.wj-header) {
    border-bottom: none;
}
 
/* ticker cell */
.ticker div {
    display: inline-block;
}
.ticker .chg {
    font-size: 75%;
    opacity: .75;
    text-align: center;
    width: 4em;
}
.ticker .glyph {
    font-size: 120%;
    text-align: center;
    width: 1em;
}
.ticker .spark {
    padding: 0 4px;
    width: 4em;
    height: 1em;
    opacity: .65;
}
.ticker .spark svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 2px;
    overflow: visible;
}
 
/* value going up */
.wj-cell:not(.wj-state-selected):not(.wj-state-multi-selected) .ticker.chg-up .chg,
.wj-cell:not(.wj-state-selected):not(.wj-state-multi-selected) .ticker.chg-up .glyph {
    color: green;
}
 
/* value going down */
.wj-cell:not(.wj-state-selected):not(.wj-state-multi-selected) .ticker.chg-down .chg,
.wj-cell:not(.wj-state-selected):not(.wj-state-multi-selected) .ticker.chg-down .glyph {
    color: red;
}
 
/* value not changing */
.ticker.chg-none .chg,
.ticker.chg-none .glyph {
    opacity: .25;
}
 
/* up/down 'flare' animations */
.ticker.flare-up:after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    animation: 1s ease-out flare-up;
}
@keyframes flare-up {
    from { background: rgba(50, 255, 50, 0.5); }
}
.ticker.flare-down:after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    animation: 1s ease-out flare-down;
}
@keyframes flare-down {
    from { background: rgba(255, 50, 50, 0.5); }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1FlexGridController : Controller
    {
        // GET: DynamicUpdates
        public ActionResult DynamicUpdates()
        {
            return View();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<h1>
    @Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Title)
</h1>
<p>
    @Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text1)
</p>
<p>
    @Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text2)
</p>
<p>
    @Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text3)
</p>
<div class="demo-settings">
    <label>@Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text4)</label>
    <input id="customCells" type="checkbox" checked="checked">
    <br />
    <label>@Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text5)</label>
    <input id="autoUpdate" type="checkbox" checked="checked">
    <br />
    <label>@Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text6)</label>
    @(Html.C1().ComboBox<int>().Id("updateInterval").Bind(new[] { 1000, 500, 100, 10, 1 }).SelectedValue(100))
    <br />
    <label>@Html.Raw(Resources.C1FlexGrid.DynamicUpdates_Text7)</label>
    @(Html.C1().ComboBox<int>().Id("batchSize").Bind(new[] { 100, 50, 10, 5, 1 }).SelectedValue(5))
</div>
 
@(Html.C1().FlexGrid().Id("theGrid")
    .IsReadOnly(true)
    .SelectionMode(C1.Web.Mvc.Grid.SelectionMode.Row)
    .AutoGenerateColumns(false)
    .Columns(cs=>
    {
        cs.Add().Binding("name").Header("Name").Width("200");
        cs.Add().Binding("bid").Header("Bid").Format("n2").Width("200");
        cs.Add().Binding("ask").Header("Ask").Format("n2").Width("200");
        cs.Add().Binding("lastSale").Header("Last Sale").Format("n2").Width("200");
        cs.Add().Binding("bidSize").Header("Bid Size").Format("n0");
        cs.Add().Binding("askSize").Header("Ask Size").Format("n0");
        cs.Add().Binding("lastSize").Header("Last Size").Format("n0");
        cs.Add().Binding("volume").Header("Volume").Format("n0");
        cs.Add().Binding("quoteTime").Header("Quote Time").Format("hh:mm:ss").Align("center");
        cs.Add().Binding("quoteTime").Header("Quote Time").Format("hh:mm:ss").Align("center");
    })
    .Filterable()
)