Skip to content

Commit

Permalink
Object selection models and plugins (#21)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Anthony Dresser authored Sep 18, 2017
1 parent 379e7d0 commit d122015
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 19 deletions.
1 change: 1 addition & 0 deletions components/js/SelectionModel.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/js/SlickGrid.js.map

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions components/js/SlickGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
@Input() showDataTypeIcon: boolean = true;
@Input() enableColumnReorder: boolean = false;
@Input() enableAsyncPostRender: boolean = false;
@Input() selectionModel: string = '';
@Input() plugins: string[] = [];
@Input() selectionModel: string | Slick.SelectionModel<any, any> = '';
@Input() plugins: Array<string | Slick.Plugin<any>> = [];
@Input() enableEditing: boolean = false;
@Input() topRowNumber: number;

Expand Down Expand Up @@ -344,8 +344,10 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
}

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

if (this._gridSyncService) {
if (this.selectionModel) {
if (Slick[this.selectionModel] && typeof Slick[this.selectionModel] === 'function') {
if (typeof this.selectionModel === 'object') {
this._gridSyncService.underlyingSelectionModel = this.selectionModel;
this._grid.setSelectionModel(this._gridSyncService.selectionModel);
} else if (typeof this.selectionModel === 'string' && Slick[this.selectionModel] && typeof Slick[this.selectionModel] === 'function') {
this._gridSyncService.underlyingSelectionModel = new Slick[this.selectionModel]();
this._grid.setSelectionModel(this._gridSyncService.selectionModel);
} else {
Expand All @@ -435,8 +440,9 @@ export class SlickGrid implements OnChanges, OnInit, OnDestroy, AfterViewInit {
this.updateColumnWidths();
});
}

for (let plugin of this.plugins) {
this.registerPlugin(plugin);
this.registerPlugin(plugin);
}

this._columnNameToIndex = {};
Expand Down
Loading

0 comments on commit d122015

Please sign in to comment.