@@ -61,12 +61,13 @@ const template = `
61
61
<slick-grid #slickgrid id="slickgrid_{{i}}" [columnDefinitions]="dataSet.columnDefinitions"
62
62
[ngClass]="i === activeGrid ? 'active' : ''"
63
63
[dataRows]="dataSet.dataRows"
64
- (contextMenu )="openContextMenu($event, dataSet.batchId, dataSet.resultId, i)"
64
+ (onContextMenu )="openContextMenu($event, dataSet.batchId, dataSet.resultId, i)"
65
65
enableAsyncPostRender="true"
66
66
showDataTypeIcon="false"
67
67
showHeader="true"
68
68
[resized]="dataSet.resized"
69
69
(mousedown)="navigateToGrid(i)"
70
+ (focusin)="setActiveGrid(i)"
70
71
[selectionModel]="selectionModel"
71
72
[plugins]="slickgridPlugins"
72
73
class="boxCol content vertBox slickgrid">
@@ -195,14 +196,14 @@ export class AppComponent implements OnInit, AfterViewChecked {
195
196
} else {
196
197
let activeGrid = this . activeGrid ;
197
198
let selection = this . slickgrids . toArray ( ) [ activeGrid ] . getSelectedRanges ( ) ;
198
- selection = this . tryCombineSelections ( selection ) ;
199
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
199
200
this . dataService . copyResults ( selection , this . renderedDataSets [ activeGrid ] . batchId , this . renderedDataSets [ activeGrid ] . resultId ) ;
200
201
}
201
202
} ,
202
203
'event.copyWithHeaders' : ( ) => {
203
204
let activeGrid = this . activeGrid ;
204
205
let selection = this . slickgrids . toArray ( ) [ activeGrid ] . getSelectedRanges ( ) ;
205
- selection = this . tryCombineSelections ( selection ) ;
206
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
206
207
this . dataService . copyResults ( selection , this . renderedDataSets [ activeGrid ] . batchId ,
207
208
this . renderedDataSets [ activeGrid ] . resultId , true ) ;
208
209
} ,
@@ -220,6 +221,22 @@ export class AppComponent implements OnInit, AfterViewChecked {
220
221
} ,
221
222
'event.saveAsExcel' : ( ) => {
222
223
this . sendSaveRequest ( 'excel' ) ;
224
+ } ,
225
+ 'event.changeColumnWidth' : async ( ) => {
226
+ const activeGrid = this . slickgrids . toArray ( ) [ this . activeGrid ] [ '_grid' ] ;
227
+ if ( activeGrid ) {
228
+ const activeCell = activeGrid . getActiveCell ( ) ;
229
+ const columns = activeGrid . getColumns ( ) ;
230
+ if ( ! columns [ activeCell . cell ] ?. resizable ) {
231
+ return ;
232
+ }
233
+ const newWidth = await this . dataService . getNewColumnWidth ( columns [ activeCell . cell ] . width ) ;
234
+ if ( newWidth ) {
235
+ columns [ activeCell . cell ] . width = newWidth ;
236
+ activeGrid . setColumns ( columns ) ;
237
+ activeGrid . setActiveCell ( activeCell . row , activeCell . cell ) ;
238
+ }
239
+ }
223
240
}
224
241
} ;
225
242
@@ -246,7 +263,7 @@ export class AppComponent implements OnInit, AfterViewChecked {
246
263
hoverText : ( ) => { return Constants . saveCSVLabel ; } ,
247
264
functionality : ( batchId , resultId , index ) => {
248
265
let selection = this . slickgrids . toArray ( ) [ index ] . getSelectedRanges ( ) ;
249
- selection = this . tryCombineSelections ( selection ) ;
266
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
250
267
if ( selection . length <= 1 ) {
251
268
this . handleContextClick ( { type : 'savecsv' , batchId : batchId , resultId : resultId , index : index , selection : selection } ) ;
252
269
} else {
@@ -260,7 +277,7 @@ export class AppComponent implements OnInit, AfterViewChecked {
260
277
hoverText : ( ) => { return Constants . saveJSONLabel ; } ,
261
278
functionality : ( batchId , resultId , index ) => {
262
279
let selection = this . slickgrids . toArray ( ) [ index ] . getSelectedRanges ( ) ;
263
- selection = this . tryCombineSelections ( selection ) ;
280
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
264
281
if ( selection . length <= 1 ) {
265
282
this . handleContextClick ( { type : 'savejson' , batchId : batchId , resultId : resultId , index : index , selection : selection } ) ;
266
283
} else {
@@ -274,7 +291,7 @@ export class AppComponent implements OnInit, AfterViewChecked {
274
291
hoverText : ( ) => { return Constants . saveExcelLabel ; } ,
275
292
functionality : ( batchId , resultId , index ) => {
276
293
let selection = this . slickgrids . toArray ( ) [ index ] . getSelectedRanges ( ) ;
277
- selection = this . tryCombineSelections ( selection ) ;
294
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
278
295
if ( selection . length <= 1 ) {
279
296
this . handleContextClick ( { type : 'saveexcel' , batchId : batchId , resultId : resultId , index : index , selection : selection } ) ;
280
297
} else {
@@ -381,16 +398,12 @@ export class AppComponent implements OnInit, AfterViewChecked {
381
398
let resultSet = event . data ;
382
399
383
400
// Setup a function for generating a promise to lookup result subsets
384
- let loadDataFunction = ( offset : number , count : number ) : Promise < IGridDataRow [ ] > => {
385
- return self . dataService . getRows ( offset , count , resultSet . batchId , resultSet . id ) . then ( rows => {
386
- let gridData : IGridDataRow [ ] = [ ] ;
387
- for ( let row = 0 ; row < rows . rows . length ; row ++ ) {
388
- // Push row values onto end of gridData for slickgrid
389
- gridData . push ( {
390
- values : rows . rows [ row ]
391
- } ) ;
401
+ let loadDataFunction = ( offset : number , count : number ) : Promise < any [ ] > => {
402
+ return self . dataService . getRows ( offset , count , resultSet . batchId , resultSet . id ) . then ( response => {
403
+ if ( ! response ) {
404
+ return [ ] ;
392
405
}
393
- return gridData ;
406
+ return response . rows ;
394
407
} ) ;
395
408
} ;
396
409
@@ -421,6 +434,7 @@ export class AppComponent implements OnInit, AfterViewChecked {
421
434
let linkType = c . isXml ? 'xml' : 'json' ;
422
435
return {
423
436
id : i . toString ( ) ,
437
+ field : i . toString ( ) ,
424
438
name : c . columnName === 'Microsoft SQL Server 2005 XML Showplan'
425
439
? 'XML Showplan'
426
440
: Utils . htmlEntities ( c . columnName ) ,
@@ -430,6 +444,16 @@ export class AppComponent implements OnInit, AfterViewChecked {
430
444
} ;
431
445
} )
432
446
} ;
447
+ dataSet . columnDefinitions . unshift ( {
448
+ id : 'rowNumber' ,
449
+ name : '' ,
450
+ field : 'rowNumber' ,
451
+ width : 22 ,
452
+ type : FieldType . Integer ,
453
+ focusable : true ,
454
+ selectable : false ,
455
+ formatter : r => { return `<span class="row-number">${ r + 1 } </span>` ; }
456
+ } ) ;
433
457
self . dataSets . push ( dataSet ) ;
434
458
435
459
// Create a dataSet to render without rows to reduce DOM size
@@ -556,10 +580,24 @@ export class AppComponent implements OnInit, AfterViewChecked {
556
580
}
557
581
}
558
582
559
- openContextMenu ( event : { x : number , y : number } , batchId , resultId , index ) : void {
560
- let selection = this . slickgrids . toArray ( ) [ index ] . getSelectedRanges ( ) ;
561
- selection = this . tryCombineSelections ( selection ) ;
562
- this . contextMenu . show ( event . x , event . y , batchId , resultId , index , selection ) ;
583
+ openContextMenu ( event : MouseEvent , batchId , resultId , index ) : void {
584
+ let selection : ISlickRange [ ] = this . slickgrids . toArray ( ) [ index ] . getSelectedRanges ( ) ;
585
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
586
+ this . contextMenu . show ( event . clientX , event . clientY , batchId , resultId , index , selection ) ;
587
+ event . preventDefault ( ) ;
588
+ event . stopPropagation ( ) ;
589
+ }
590
+
591
+ private tryCombineSelectionsForResults ( selections : ISlickRange [ ] ) : ISlickRange [ ] {
592
+ // need to take row number column in to consideration.
593
+ return this . tryCombineSelections ( selections ) . map ( range => {
594
+ return {
595
+ fromCell : range . fromCell - 1 ,
596
+ fromRow : range . fromRow ,
597
+ toCell : range . toCell - 1 ,
598
+ toRow : range . toRow
599
+ } ;
600
+ } ) ;
563
601
}
564
602
565
603
private tryCombineSelections ( selections : ISlickRange [ ] ) : ISlickRange [ ] {
@@ -598,7 +636,7 @@ export class AppComponent implements OnInit, AfterViewChecked {
598
636
let batchId = this . renderedDataSets [ activeGrid ] . batchId ;
599
637
let resultId = this . renderedDataSets [ activeGrid ] . resultId ;
600
638
let selection = this . slickgrids . toArray ( ) [ activeGrid ] . getSelectedRanges ( ) ;
601
- selection = this . tryCombineSelections ( selection ) ;
639
+ selection = this . tryCombineSelectionsForResults ( selection ) ;
602
640
this . dataService . sendSaveRequest ( batchId , resultId , format , selection ) ;
603
641
}
604
642
@@ -904,6 +942,27 @@ export class AppComponent implements OnInit, AfterViewChecked {
904
942
* @returns A boolean representing if the navigation was successful
905
943
*/
906
944
navigateToGrid ( targetIndex : number ) : boolean {
945
+ const result = this . setActiveGrid ( targetIndex ) ;
946
+ if ( ! result ) { return false ; }
947
+
948
+ // scrolling logic
949
+ let resultsWindow = $ ( '#results' ) ;
950
+ let scrollTop = resultsWindow . scrollTop ( ) ;
951
+ let scrollBottom = scrollTop + resultsWindow . height ( ) ;
952
+ let gridHeight = $ ( this . _el . nativeElement ) . find ( 'slick-grid' ) . height ( ) ;
953
+ if ( scrollBottom < gridHeight * ( targetIndex + 1 ) ) {
954
+ scrollTop += ( gridHeight * ( targetIndex + 1 ) ) - scrollBottom ;
955
+ resultsWindow . scrollTop ( scrollTop ) ;
956
+ }
957
+ if ( scrollTop > gridHeight * targetIndex ) {
958
+ scrollTop = ( gridHeight * targetIndex ) ;
959
+ resultsWindow . scrollTop ( scrollTop ) ;
960
+ }
961
+
962
+ return true ;
963
+ }
964
+
965
+ setActiveGrid ( targetIndex : number ) : boolean {
907
966
// check if the target index is valid
908
967
if ( targetIndex >= this . renderedDataSets . length || targetIndex < 0 ) {
909
968
return false ;
@@ -921,21 +980,6 @@ export class AppComponent implements OnInit, AfterViewChecked {
921
980
this . slickgrids . toArray ( ) [ this . activeGrid ] . selection = false ;
922
981
this . slickgrids . toArray ( ) [ targetIndex ] . setActive ( ) ;
923
982
this . activeGrid = targetIndex ;
924
-
925
- // scrolling logic
926
- let resultsWindow = $ ( '#results' ) ;
927
- let scrollTop = resultsWindow . scrollTop ( ) ;
928
- let scrollBottom = scrollTop + resultsWindow . height ( ) ;
929
- let gridHeight = $ ( this . _el . nativeElement ) . find ( 'slick-grid' ) . height ( ) ;
930
- if ( scrollBottom < gridHeight * ( targetIndex + 1 ) ) {
931
- scrollTop += ( gridHeight * ( targetIndex + 1 ) ) - scrollBottom ;
932
- resultsWindow . scrollTop ( scrollTop ) ;
933
- }
934
- if ( scrollTop > gridHeight * targetIndex ) {
935
- scrollTop = ( gridHeight * targetIndex ) ;
936
- resultsWindow . scrollTop ( scrollTop ) ;
937
- }
938
-
939
983
return true ;
940
984
}
941
985
0 commit comments