diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts b/aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts index 8532c38f9..964911710 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/aurelia-slickgrid.ts @@ -353,6 +353,14 @@ export class AureliaSlickgridCustomElement { grid.invalidateRows(args.rows); grid.render(); }); + + // does the user have a colspan callback? + if (gridOptions.colspanCallback) { + dataView.getItemMetadata = (rowNumber: number) => { + const item = dataView.getItem(rowNumber); + return gridOptions.colspanCallback(item); + }; + } } attachBackendCallbackFunctions(gridOptions: GridOption) { diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/models/gridOption.interface.ts b/aurelia-slickgrid/src/aurelia-slickgrid/models/gridOption.interface.ts index 32919d8bb..107acafec 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/models/gridOption.interface.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/models/gridOption.interface.ts @@ -14,7 +14,6 @@ import { HeaderMenu, Pagination } from './../models/index'; -import { BooleanLiteral, NumberLiteralType } from 'typescript'; export interface GridOption { /** CSS class name used on newly added row */ @@ -65,6 +64,9 @@ export interface GridOption { /** Checkbox Select Plugin options (columnId, cssClass, toolTip, width) */ checkboxSelector?: CheckboxSelector; + /** A callback function that will be used to define row spanning accross multiple columns */ + colspanCallback?: (item: any) => { columns: any }; + /** Checkbox Select Plugin options (columnTitle, forceFitTitle, syncResizeTitle) */ columnPicker?: ColumnPicker; diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/services/groupingAndColspan.service.ts b/aurelia-slickgrid/src/aurelia-slickgrid/services/groupingAndColspan.service.ts index c8377193b..8dfca4a1a 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/services/groupingAndColspan.service.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/services/groupingAndColspan.service.ts @@ -30,24 +30,26 @@ export class GroupingAndColspanService { this.aureliaEventPrefix = (this._gridOptions && this._gridOptions.defaultAureliaEventPrefix) ? this._gridOptions.defaultAureliaEventPrefix : 'asg'; - // When dealing with Pre-Header Grouping colspan, we need to re-create the pre-header in multiple occasions - // for all these occasions, we have to trigger a re-create - if (this._gridOptions.createPreHeaderPanel) { - this._eventHandler.subscribe(grid.onSort, (e: Event, args: any) => { - this.createPreHeaderRowGroupingTitle(); - }); - this._eventHandler.subscribe(grid.onColumnsResized, (e: Event, args: any) => { - this.createPreHeaderRowGroupingTitle(); - }); - this._eventHandler.subscribe(dataView.onRowCountChanged, (e: Event, args: any) => { - this.createPreHeaderRowGroupingTitle(); - }); + if (grid && this._gridOptions) { + // When dealing with Pre-Header Grouping colspan, we need to re-create the pre-header in multiple occasions + // for all these occasions, we have to trigger a re-create + if (this._gridOptions.createPreHeaderPanel) { + this._eventHandler.subscribe(grid.onSort, (e: Event, args: any) => { + this.createPreHeaderRowGroupingTitle(); + }); + this._eventHandler.subscribe(grid.onColumnsResized, (e: Event, args: any) => { + this.createPreHeaderRowGroupingTitle(); + }); + this._eventHandler.subscribe(dataView.onRowCountChanged, (e: Event, args: any) => { + this.createPreHeaderRowGroupingTitle(); + }); - // also not sure why at this point, but it seems that I need to call the 1st create in a delayed execution - // probably some kind of timing issues and delaying it until the grid is fully ready does help - setTimeout(() => { - this.createPreHeaderRowGroupingTitle(); - }, 50); + // also not sure why at this point, but it seems that I need to call the 1st create in a delayed execution + // probably some kind of timing issues and delaying it until the grid is fully ready does help + setTimeout(() => { + this.createPreHeaderRowGroupingTitle(); + }, 50); + } } } diff --git a/aurelia-slickgrid/src/examples/slickgrid/example14.html b/aurelia-slickgrid/src/examples/slickgrid/example14.html index df0b1d0bb..bdd449b75 100644 --- a/aurelia-slickgrid/src/examples/slickgrid/example14.html +++ b/aurelia-slickgrid/src/examples/slickgrid/example14.html @@ -3,6 +3,6 @@

${title}

+ grid-height="500" grid-width="800"> diff --git a/aurelia-slickgrid/src/examples/slickgrid/example14.ts b/aurelia-slickgrid/src/examples/slickgrid/example14.ts index 75c05919c..722adcff1 100644 --- a/aurelia-slickgrid/src/examples/slickgrid/example14.ts +++ b/aurelia-slickgrid/src/examples/slickgrid/example14.ts @@ -6,11 +6,8 @@ import * as $ from 'jquery'; export class Example14 { title = 'Example 14: Column Span & Header Grouping'; subTitle = ` - This example demonstrates how to easily span a column over multiple columns. + This example demonstrates how to easily span a row over multiple columns & how to group header titles.