Skip to content

Object selection models and plugins #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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