Skip to content

Commit d122015

Browse files
author
Anthony Dresser
authored
Object selection models and plugins (#21)
* added an option to register a plugin object * change plugin inputtype of allow plugin objects * recompile * allowe selection model objects * recompile * added source maps * add slickgrid to typings; change overload function to just use union
1 parent 379e7d0 commit d122015

15 files changed

+53
-19
lines changed

components/js/SelectionModel.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/js/SlickGrid.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/js/SlickGrid.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
132132
@Input() showDataTypeIcon: boolean = true;
133133
@Input() enableColumnReorder: boolean = false;
134134
@Input() enableAsyncPostRender: boolean = false;
135-
@Input() selectionModel: string = '';
136-
@Input() plugins: string[] = [];
135+
@Input() selectionModel: string | Slick.SelectionModel<any, any> = '';
136+
@Input() plugins: Array<string | Slick.Plugin<any>> = [];
137137
@Input() enableEditing: boolean = false;
138138
@Input() topRowNumber: number;
139139

@@ -344,8 +344,10 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
344344
}
345345

346346
// Registers a Slick plugin with the given name
347-
public registerPlugin(plugin: string): void {
348-
if (Slick[plugin] && typeof Slick[plugin] === 'function') {
347+
public registerPlugin(plugin: Slick.Plugin<any> | string): void {
348+
if (typeof plugin === 'object') {
349+
this._grid.registerPlugin(plugin);
350+
} else if (typeof plugin === 'string' && Slick[plugin] && typeof Slick[plugin] === 'function') {
349351
this._grid.registerPlugin(new Slick[plugin]);
350352
} else {
351353
console.error(`Tried to register plugin ${plugin}, but none was found to be attached to Slick Grid or it was not a function.
@@ -418,7 +420,10 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
418420

419421
if (this._gridSyncService) {
420422
if (this.selectionModel) {
421-
if (Slick[this.selectionModel] && typeof Slick[this.selectionModel] === 'function') {
423+
if (typeof this.selectionModel === 'object') {
424+
this._gridSyncService.underlyingSelectionModel = this.selectionModel;
425+
this._grid.setSelectionModel(this._gridSyncService.selectionModel);
426+
} else if (typeof this.selectionModel === 'string' && Slick[this.selectionModel] && typeof Slick[this.selectionModel] === 'function') {
422427
this._gridSyncService.underlyingSelectionModel = new Slick[this.selectionModel]();
423428
this._grid.setSelectionModel(this._gridSyncService.selectionModel);
424429
} else {
@@ -435,8 +440,9 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
435440
this.updateColumnWidths();
436441
});
437442
}
443+
438444
for (let plugin of this.plugins) {
439-
this.registerPlugin(plugin);
445+
this.registerPlugin(plugin);
440446
}
441447

442448
this._columnNameToIndex = {};

0 commit comments

Comments
 (0)