diff --git a/src/app/examples/custom-inputEditor.ts b/src/app/examples/custom-inputEditor.ts new file mode 100644 index 000000000..a6b181849 --- /dev/null +++ b/src/app/examples/custom-inputEditor.ts @@ -0,0 +1,80 @@ +import { Editor, KeyCode } from './../modules/angular-slickgrid'; + +// using external non-typed js libraries +declare var $: any; + +/* + * An example of a 'detached' editor. + * KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter. + */ +export class CustomInputEditor implements Editor { + $input: any; + defaultValue: any; + + constructor(private args: any) { + this.init(); + } + + init(): void { + this.$input = $(``) + .appendTo(this.args.container) + .on('keydown.nav', (e) => { + if (e.keyCode === KeyCode.LEFT || e.keyCode === KeyCode.RIGHT) { + e.stopImmediatePropagation(); + } + }); + + setTimeout(() => { + this.$input.focus().select(); + }, 50); + } + + destroy() { + this.$input.remove(); + } + + focus() { + this.$input.focus(); + } + + getValue() { + return this.$input.val(); + } + + setValue(val: string) { + this.$input.val(val); + } + + loadValue(item: any) { + this.defaultValue = item[this.args.column.field] || ''; + this.$input.val(this.defaultValue); + this.$input[0].defaultValue = this.defaultValue; + this.$input.select(); + } + + serializeValue() { + return this.$input.val(); + } + + applyValue(item: any, state: any) { + item[this.args.column.field] = state; + } + + isValueChanged() { + return (!(this.$input.val() === '' && this.defaultValue === null)) && (this.$input.val() !== this.defaultValue); + } + + validate() { + if (this.args.column.validator) { + const validationResults = this.args.column.validator(this.$input.val()); + if (!validationResults.valid) { + return validationResults; + } + } + + return { + valid: true, + msg: null + }; + } +} diff --git a/src/app/examples/grid-additem.component.ts b/src/app/examples/grid-additem.component.ts index ff8b7aaec..8673271a9 100644 --- a/src/app/examples/grid-additem.component.ts +++ b/src/app/examples/grid-additem.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, Injectable } from '@angular/core'; -import { AngularGridInstance, Column, Editors, FieldType, Formatters, GridOption, OnEventArgs } from './../modules/angular-slickgrid'; +import { AngularGridInstance, Column, EditorType, FieldType, Formatters, GridOption, OnEventArgs } from './../modules/angular-slickgrid'; @Component({ templateUrl: './grid-additem.component.html' @@ -33,17 +33,58 @@ export class GridAddItemComponent implements OnInit { ngOnInit(): void { this.columnDefinitions = [ - { id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, editor: Editors.longText }, - { id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, editor: Editors.text, + { + id: 'title', name: 'Title', field: 'title', + sortable: true, + type: FieldType.string, + editor: { + type: EditorType.longText + } + }, + { + id: 'duration', name: 'Duration (days)', field: 'duration', + sortable: true, + type: FieldType.number, + editor: { + type: EditorType.text + }, onCellChange: (args: OnEventArgs) => { alert('onCellChange directly attached to the column definition'); console.log(args); } }, - { id: 'complete', name: '% Complete', field: 'percentComplete', formatter: Formatters.percentCompleteBar, type: FieldType.number, editor: Editors.integer }, - { id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.date/*, editor: Editors.date*/ }, - { id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, sortable: true, type: FieldType.date }, - { id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: Formatters.checkmark, type: FieldType.number, editor: Editors.checkbox } + { + id: 'complete', name: '% Complete', field: 'percentComplete', + formatter: Formatters.percentCompleteBar, + type: FieldType.number, + editor: { + type: EditorType.integer + } + }, + { + id: 'start', name: 'Start', field: 'start', + formatter: Formatters.dateIso, + sortable: true, + type: FieldType.date, + /* + editor: { + type: EditorType.date + } + */ + }, + { + id: 'finish', name: 'Finish', field: 'finish', + formatter: Formatters.dateIso, sortable: true, + type: FieldType.date + }, + { + id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', + formatter: Formatters.checkmark, + type: FieldType.number, + editor: { + type: EditorType.checkbox + } + } ]; this.gridOptions = { diff --git a/src/app/examples/grid-editor.component.ts b/src/app/examples/grid-editor.component.ts index 35d76ef11..2d46ff344 100644 --- a/src/app/examples/grid-editor.component.ts +++ b/src/app/examples/grid-editor.component.ts @@ -3,12 +3,13 @@ import { TranslateService } from '@ngx-translate/core'; import { AngularGridInstance, Column, - Editors, + EditorType, FieldType, Formatters, GridOption, OnEventArgs } from './../modules/angular-slickgrid'; +import { CustomInputEditor } from './custom-inputEditor'; // using external non-typed js libraries declare var Slick: any; @@ -84,20 +85,35 @@ export class GridEditorComponent implements OnInit { field: 'title', sortable: true, type: FieldType.string, - editor: Editors.longText, + editor: { + type: EditorType.longText + }, minWidth: 100, onCellChange: (args: OnEventArgs) => { console.log(args); this.alertWarning = `Updated Title: ${args.dataContext.title}`; } + }, { + id: 'title2', + name: 'Title, Custom Editor', + field: 'title', + sortable: true, + type: FieldType.string, + editor: { + type: EditorType.custom, + customEditor: CustomInputEditor + }, + minWidth: 70 }, { id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, - editor: Editors.float, - params: { decimalPlaces: 2 }, + editor: { + type: EditorType.float, + params: { decimalPlaces: 2 }, + }, minWidth: 100 }, { id: 'complete', @@ -105,15 +121,18 @@ export class GridEditorComponent implements OnInit { field: 'percentComplete', formatter: Formatters.multiple, type: FieldType.number, - editor: Editors.singleSelect, - minWidth: 100, - params: { - formatters: [ Formatters.collection, Formatters.percentCompleteBar ], + editor: { + type: EditorType.singleSelect, collection: Array.from(Array(101).keys()).map(k => ({ value: k, label: k })), collectionSortBy: { property: 'label', sortDesc: true - }, + } + }, + minWidth: 100, + params: { + collection: Array.from(Array(101).keys()).map(k => ({ value: k, label: k })), + formatters: [ Formatters.collection, Formatters.percentCompleteBar ] } }, { id: 'start', @@ -123,7 +142,9 @@ export class GridEditorComponent implements OnInit { sortable: true, minWidth: 100, type: FieldType.date, - editor: Editors.date + editor: { + type: EditorType.date + } }, { id: 'finish', name: 'Finish', @@ -132,14 +153,18 @@ export class GridEditorComponent implements OnInit { sortable: true, minWidth: 100, type: FieldType.date, - editor: Editors.date + editor: { + type: EditorType.date + } }, { id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: Formatters.checkmark, type: FieldType.number, - editor: Editors.checkbox, + editor: { + type: EditorType.checkbox + }, minWidth: 60 }, { id: 'prerequisites', @@ -147,9 +172,8 @@ export class GridEditorComponent implements OnInit { field: 'prerequisites', sortable: true, type: FieldType.string, - editor: Editors.multipleSelect, - minWidth: 100, - params: { + editor: { + type: EditorType.multipleSelect, collection: Array.from(Array(12).keys()).map(k => ({ value: `Task ${k}`, label: `Task ${k}` })), collectionSortBy: { property: 'label', @@ -159,7 +183,8 @@ export class GridEditorComponent implements OnInit { property: 'label', value: 'Task 2' } - } + }, + minWidth: 100 }]; this.gridOptions = { diff --git a/src/app/examples/swt-common-grid.component.ts b/src/app/examples/swt-common-grid.component.ts index 25eddd7ea..7ceb84e98 100644 --- a/src/app/examples/swt-common-grid.component.ts +++ b/src/app/examples/swt-common-grid.component.ts @@ -3,7 +3,7 @@ import { Component, OnInit, Injectable, ViewContainerRef, ComponentFactoryResolv AfterViewInit, Input, EventEmitter, Output, ViewChild , ElementRef, Renderer} from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { AngularSlickgridComponent, Column, Editors, FieldType, Formatter, Formatters, +import { AngularSlickgridComponent, Column, FieldType, Formatter, Formatters, GridOption, OnEventArgs, BackendService, BackendServiceOption, FilterChangedArgs, PaginationChangedArgs, SortChangedArgs, Pagination} from '../modules/angular-slickgrid'; import { TranslateService } from '@ngx-translate/core'; diff --git a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts index ec1f349e8..40152f9c4 100644 --- a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts +++ b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts @@ -19,11 +19,22 @@ import 'slickgrid/plugins/slick.headerbuttons'; import 'slickgrid/plugins/slick.headermenu'; import 'slickgrid/plugins/slick.rowmovemanager'; import 'slickgrid/plugins/slick.rowselectionmodel'; -import { AfterViewInit, Component, EventEmitter, Inject, Injectable, Input, Output, OnDestroy, OnInit, ViewChildren, ElementRef, ViewChild } from '@angular/core'; +import { AfterViewInit, Component, EventEmitter, Inject, Injectable, Input, Output, OnDestroy, OnInit, ViewChildren, ElementRef, ViewChild, ReflectiveInjector } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { castToPromise, toKebabCase } from './../services/utilities'; import { GlobalGridOptions } from './../global-grid-options'; -import { AngularGridInstance, BackendServiceOption, Column, GridOption, GridStateChange, GridStateType, Pagination } from './../models/index'; +import { + AngularGridInstance, + BackendServiceOption, + Column, + Editor, + EditorType, + GridOption, + GridStateChange, + GridStateType, + Pagination +} from './../models/index'; +import { Editors, AVAILABLE_EDITORS } from './../editors/index'; import { ControlAndPluginService } from './../services/controlAndPlugin.service'; import { ExportService } from './../services/export.service'; import { FilterService } from './../services/filter.service'; @@ -108,6 +119,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn return this._dataView.getItems(); } + constructor( private controlAndPluginService: ControlAndPluginService, private exportService: ExportService, @@ -177,6 +189,12 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn this._dataView = new Slick.Data.DataView(); } + // for convenience, we provide the property "editor" as an Angular-Slickgrid editor complex object + // however "editor" is used internally by SlickGrid for it's Editor Factory + // so in our lib we will swap "editor" and copy it into "internalColumnEditor" + // then take back "editor.type" and make it the new "editor" so that SlickGrid Editor Factory still works + this._columnDefinitions = this._columnDefinitions.map((c: Column | any) => ({ ...c, editor: this.getEditor((c.editor && c.editor.type), c), internalColumnEditor: { ...c.editor } })), + this.controlAndPluginService.createPluginBeforeGridCreation(this._columnDefinitions, this.gridOptions); this.grid = new Slick.Grid(`#${this.gridId}`, this._dataView, this._columnDefinitions, this.gridOptions); @@ -238,6 +256,25 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn }); } + /** + * From the list of available editors, find the editor associated to it's type + * and if it's a custom one, return the "customEditor" from the column + * @param type + * @param column + */ + getEditor(type: EditorType, column: Column) { + if (type === EditorType.custom && column && column.editor && column.editor.hasOwnProperty('customEditor')) { + return column.editor['customEditor']; + } + + const editorFound = AVAILABLE_EDITORS.find(editor => editor.type === type); + if (editorFound && editorFound.editor) { + return editorFound.editor; + } + + return undefined; + } + /** * Define what our internal Post Process callback, it will execute internally after we get back result from the Process backend call * For now, this is GraphQL Service only feautre and it will basically refresh the Dataset & Pagination without having the user to create his own PostProcess every time @@ -477,7 +514,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn if (this.grid && this.gridOptions.enableAutoResize) { // resize the grid inside a slight timeout, in case other DOM element changed prior to the resize (like a filter/pagination changed) this.resizer.resizeGrid(10, { height: this.gridHeight, width: this.gridWidth }); - // this.grid.autosizeColumns(); } } } diff --git a/src/app/modules/angular-slickgrid/editors/dateEditor.ts b/src/app/modules/angular-slickgrid/editors/dateEditor.ts index 99f1aea9b..2ce90c32f 100644 --- a/src/app/modules/angular-slickgrid/editors/dateEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/dateEditor.ts @@ -56,7 +56,7 @@ export class DateEditor implements Editor { } getCurrentLocale(columnDef: Column, gridOptions: GridOption) { - const params = gridOptions.params || columnDef.params || {}; + const params = gridOptions || columnDef.params || {}; if (params.i18n && params.i18n instanceof TranslateService) { return params.i18n.currentLang; } diff --git a/src/app/modules/angular-slickgrid/editors/floatEditor.ts b/src/app/modules/angular-slickgrid/editors/floatEditor.ts index 77e70adb8..e37796880 100644 --- a/src/app/modules/angular-slickgrid/editors/floatEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/floatEditor.ts @@ -41,8 +41,8 @@ export class FloatEditor implements Editor { getDecimalPlaces() { // returns the number of fixed decimal places or null - const columnParams = this.args.column.params || {}; - let rtn = (columnParams && columnParams.hasOwnProperty('decimalPlaces')) ? columnParams.decimalPlaces : undefined; + const columnEditor = this.args && this.args.column && this.args.column.internalColumnEditor && this.args.column.internalColumnEditor; + let rtn = (columnEditor && columnEditor.params && columnEditor.params.hasOwnProperty('decimalPlaces')) ? columnEditor.params.decimalPlaces : undefined; if (rtn === undefined) { rtn = defaultDecimalPlaces; } diff --git a/src/app/modules/angular-slickgrid/editors/index.ts b/src/app/modules/angular-slickgrid/editors/index.ts index 8054c9059..671a08bfe 100644 --- a/src/app/modules/angular-slickgrid/editors/index.ts +++ b/src/app/modules/angular-slickgrid/editors/index.ts @@ -1,3 +1,4 @@ +import { EditorType } from './../models/editorType.enum'; import { CheckboxEditor } from './checkboxEditor'; import { DateEditor } from './dateEditor'; import { FloatEditor } from './floatEditor'; @@ -6,6 +7,11 @@ import { LongTextEditor } from './longTextEditor'; import { MultipleSelectEditor } from './multipleSelectEditor'; import { SingleSelectEditor } from './singleSelectEditor'; import { TextEditor } from './textEditor'; +import { Editor } from '../models'; + +export class AvailableEditor { + constructor(public type: EditorType, public editor: any) {} +} export const Editors = { checkbox: CheckboxEditor, @@ -17,3 +23,14 @@ export const Editors = { singleSelect: SingleSelectEditor, text: TextEditor }; + +export const AVAILABLE_EDITORS: AvailableEditor[] = [ + { type: EditorType.checkbox, editor: CheckboxEditor }, + { type: EditorType.date, editor: DateEditor }, + { type: EditorType.float, editor: FloatEditor }, + { type: EditorType.integer, editor: IntegerEditor }, + { type: EditorType.longText, editor: LongTextEditor }, + { type: EditorType.multipleSelect, editor: MultipleSelectEditor }, + { type: EditorType.singleSelect, editor: SingleSelectEditor }, + { type: EditorType.text, editor: TextEditor }, +]; diff --git a/src/app/modules/angular-slickgrid/editors/multipleSelectEditor.ts b/src/app/modules/angular-slickgrid/editors/multipleSelectEditor.ts index 635cef489..32bca38fc 100644 --- a/src/app/modules/angular-slickgrid/editors/multipleSelectEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/multipleSelectEditor.ts @@ -91,29 +91,29 @@ export class MultipleSelectEditor implements Editor { throw new Error('[Angular-SlickGrid] An editor must always have an "init()" with valid arguments.'); } - this.columnDef = this.args.column; + this.columnDef = this.args.column as Column; - if (!this.columnDef || !this.columnDef.params || !this.columnDef.params.collection) { - throw new Error(`[Angular-SlickGrid] You need to pass a "collection" on the params property in the column definition for the MultipleSelect Editor to work correctly. + if (!this.columnDef || !this.columnDef.internalColumnEditor || !this.columnDef.internalColumnEditor.collection) { + throw new Error(`[Angular-SlickGrid] You need to pass a "collection" inside Column Definition Editor for the MultipleSelect Editor to work correctly. Also each option should include a value/label pair (or value/labelKey when using Locale). - For example: { params: { { collection: [{ value: true, label: 'True' },{ value: false, label: 'False'}] } } }`); + For example: { editor: { collection: [{ value: true, label: 'True' },{ value: false, label: 'False'}] } }`); } const collectionService = new CollectionService(this._translate); - this.enableTranslateLabel = (this.columnDef.params.enableTranslateLabel) ? this.columnDef.params.enableTranslateLabel : false; - let newCollection = this.columnDef.params.collection || []; - this.labelName = (this.columnDef.params.customStructure) ? this.columnDef.params.customStructure.label : 'label'; - this.valueName = (this.columnDef.params.customStructure) ? this.columnDef.params.customStructure.value : 'value'; + this.enableTranslateLabel = (this.columnDef.internalColumnEditor.enableTranslateLabel) ? this.columnDef.internalColumnEditor.enableTranslateLabel : false; + let newCollection = this.columnDef.internalColumnEditor.collection || []; + this.labelName = (this.columnDef.internalColumnEditor.customStructure) ? this.columnDef.internalColumnEditor.customStructure.label : 'label'; + this.valueName = (this.columnDef.internalColumnEditor.customStructure) ? this.columnDef.internalColumnEditor.customStructure.value : 'value'; // user might want to filter certain items of the collection - if (this.columnDef.params && this.columnDef.params.collectionSortBy) { - const filterBy = this.columnDef.params.collectionFilterBy; + if (this.columnDef.internalColumnEditor && this.columnDef.internalColumnEditor.collectionSortBy) { + const filterBy = this.columnDef.internalColumnEditor.collectionFilterBy; newCollection = collectionService.filterCollection(newCollection, filterBy); } // user might want to sort the collection - if (this.gridOptions.params && this.columnDef.params.collectionSortBy) { - const sortBy = this.columnDef.params.collectionSortBy; + if (this.columnDef.internalColumnEditor && this.columnDef.internalColumnEditor.collectionSortBy) { + const sortBy = this.columnDef.internalColumnEditor.collectionSortBy; newCollection = collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel); } @@ -234,7 +234,7 @@ export class MultipleSelectEditor implements Editor { // fallback to bootstrap this.$editorElm.addClass('form-control'); } else { - const elementOptions = (this.columnDef.params) ? this.columnDef.params.elementOptions : {}; + const elementOptions = (this.columnDef.internalColumnEditor) ? this.columnDef.internalColumnEditor.elementOptions : {}; this.editorElmOptions = { ...this.defaultOptions, ...elementOptions }; this.$editorElm = this.$editorElm.multipleSelect(this.editorElmOptions); setTimeout(() => this.$editorElm.multipleSelect('open')); diff --git a/src/app/modules/angular-slickgrid/editors/singleSelectEditor.ts b/src/app/modules/angular-slickgrid/editors/singleSelectEditor.ts index 07ef51b54..04cf620d0 100644 --- a/src/app/modules/angular-slickgrid/editors/singleSelectEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/singleSelectEditor.ts @@ -84,27 +84,27 @@ export class SingleSelectEditor implements Editor { this.columnDef = this.args.column; - if (!this.columnDef || !this.columnDef.params || !this.columnDef.params.collection) { - throw new Error(`[Angular-SlickGrid] You need to pass a "collection" on the params property in the column definition for the MultipleSelect Editor to work correctly. + if (!this.columnDef || !this.columnDef.internalColumnEditor || !this.columnDef.internalColumnEditor.collection) { + throw new Error(`[Angular-SlickGrid] You need to pass a "collection" inside Column Definition Editor for the SingleSelect Editor to work correctly. Also each option should include a value/label pair (or value/labelKey when using Locale). - For example: { params: { { collection: [{ value: true, label: 'True' },{ value: false, label: 'False'}] } } }`); + For example: { editor: { collection: [{ value: true, label: 'True' },{ value: false, label: 'False'}] } }`); } const collectionService = new CollectionService(this._translate); - this.enableTranslateLabel = (this.columnDef.params.enableTranslateLabel) ? this.columnDef.params.enableTranslateLabel : false; - let newCollection = this.columnDef.params.collection || []; - this.labelName = (this.columnDef.params.customStructure) ? this.columnDef.params.customStructure.label : 'label'; - this.valueName = (this.columnDef.params.customStructure) ? this.columnDef.params.customStructure.value : 'value'; + this.enableTranslateLabel = (this.columnDef.internalColumnEditor.enableTranslateLabel) ? this.columnDef.internalColumnEditor.enableTranslateLabel : false; + let newCollection = this.columnDef.internalColumnEditor.collection || []; + this.labelName = (this.columnDef.internalColumnEditor.customStructure) ? this.columnDef.internalColumnEditor.customStructure.label : 'label'; + this.valueName = (this.columnDef.internalColumnEditor.customStructure) ? this.columnDef.internalColumnEditor.customStructure.value : 'value'; // user might want to filter certain items of the collection - if (this.gridOptions.params && this.columnDef.params.collectionFilterBy) { - const filterBy = this.columnDef.params.collectionFilterBy; + if (this.columnDef.internalColumnEditor && this.columnDef.internalColumnEditor.collectionFilterBy) { + const filterBy = this.columnDef.internalColumnEditor.collectionFilterBy; newCollection = collectionService.filterCollection(newCollection, filterBy); } // user might want to sort the collection - if (this.columnDef.params && this.columnDef.params.collectionSortBy) { - const sortBy = this.columnDef.params.collectionSortBy; + if (this.columnDef.internalColumnEditor && this.columnDef.internalColumnEditor.collectionSortBy) { + const sortBy = this.columnDef.internalColumnEditor.collectionSortBy; newCollection = collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel); } diff --git a/src/app/modules/angular-slickgrid/editors/textEditor.ts b/src/app/modules/angular-slickgrid/editors/textEditor.ts index bd0840052..0502f620c 100644 --- a/src/app/modules/angular-slickgrid/editors/textEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/textEditor.ts @@ -16,7 +16,7 @@ export class TextEditor implements Editor { } init(): void { - this.$input = $(``) + this.$input = $(``) .appendTo(this.args.container) .on('keydown.nav', (e) => { if (e.keyCode === KeyCode.LEFT || e.keyCode === KeyCode.RIGHT) { diff --git a/src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts b/src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts index 477894a79..9b2584f1a 100644 --- a/src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts +++ b/src/app/modules/angular-slickgrid/filters/compoundInputFilter.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { FieldType } from './../models/fieldType'; +import { FieldType } from './../models/index'; import { Column, Filter, FilterArguments, FilterCallback, GridOption, OperatorString, OperatorType, SearchTerm } from './../models/index'; import { htmlEntityEncode } from '..'; diff --git a/src/app/modules/angular-slickgrid/models/column.interface.ts b/src/app/modules/angular-slickgrid/models/column.interface.ts index 522eacdfb..db80b1398 100644 --- a/src/app/modules/angular-slickgrid/models/column.interface.ts +++ b/src/app/modules/angular-slickgrid/models/column.interface.ts @@ -1,6 +1,8 @@ +import { ColumnEditor } from './columnEditor.interface'; import { ColumnFilter } from './columnFilter.interface'; import { Editor } from './editor.interface'; -import { FieldType } from './fieldType'; +import { EditorType } from './editorType.enum'; +import { FieldType } from './fieldType.enum'; import { Formatter } from './formatter.interface'; import { GroupTotalsFormatter } from './groupTotalsFormatter.interface'; import { HeaderButtonItem } from './headerButtonItem.interface'; @@ -28,7 +30,7 @@ export interface Column { defaultSortAsc?: boolean; /** Inline editor for the cell value */ - editor?: Editor | any; + editor?: EditorType | ColumnEditor; /** Default to false, which leads to exclude the column from the export? */ excludeFromExport?: boolean; @@ -104,6 +106,11 @@ export interface Column { /** ID of the column, each row have to be unique or SlickGrid will throw an error. */ id: number | string; + /** + * @internal used internally by Angular-Slickgrid, to copy over the Column Editor Options + */ + internalColumnEditor?: any; + /** is the column editable? Goes with grid option "editable: true". */ isEditable?: boolean; diff --git a/src/app/modules/angular-slickgrid/models/columnEditor.interface.ts b/src/app/modules/angular-slickgrid/models/columnEditor.interface.ts new file mode 100644 index 000000000..e9eb6ef4a --- /dev/null +++ b/src/app/modules/angular-slickgrid/models/columnEditor.interface.ts @@ -0,0 +1,51 @@ +import { EditorType } from './editorType.enum'; +import { TextEditor } from './../editors/textEditor'; +import { SingleSelectEditor } from './../editors/singleSelectEditor'; +import { MultipleSelectEditor } from './../editors/multipleSelectEditor'; +import { LongTextEditor } from './../editors/longTextEditor'; +import { IntegerEditor } from './../editors/integerEditor'; +import { FloatEditor } from './../editors/floatEditor'; +import { DateEditor } from './../editors/dateEditor'; +import { CheckboxEditor } from './../editors/checkboxEditor'; +import { + CollectionFilterBy, + CollectionSortBy, + Editor, + MultipleSelectOption +} from './../models/index'; + +export interface ColumnEditor { + /** Custom Editor */ + customEditor?: any; + + /** Editor Type to use (input, multipleSelect, singleSelect, select, custom) */ + type?: EditorType; + + collection?: any[]; + + /** We could filter some items from the collection */ + collectionFilterBy?: CollectionFilterBy; + + /** We could sort the collection by their value, or by translated value when enableTranslateLabel is True */ + collectionSortBy?: CollectionSortBy; + + /** Options that could be provided to the Editor, example: { container: 'body', maxHeight: 250} */ + editorOptions?: MultipleSelectOption | any; + + /** Do we want the Editor to handle translation (localization)? */ + enableTranslateLabel?: boolean; + + /** A custom structure can be used instead of the default label/value pair. Commonly used with Select/Multi-Select Editor */ + customStructure?: { + label: string; + value: string; + }; + + /** + * Use "params" to pass any type of arguments to your Custom Editor (type: EditorType.custom) + * or regular Editor like the EditorType.float + * for example, to pass the option collection to a select Filter we can type this: + * params: { decimalPlaces: 2 } + */ + params?: any; +} diff --git a/src/app/modules/angular-slickgrid/models/editorType.enum.ts b/src/app/modules/angular-slickgrid/models/editorType.enum.ts new file mode 100644 index 000000000..df79b99fa --- /dev/null +++ b/src/app/modules/angular-slickgrid/models/editorType.enum.ts @@ -0,0 +1,28 @@ +export enum EditorType { + /** Custom Editor type */ + custom, + + /** Checkbox Editor */ + checkbox, + + /** Date Picker Editor */ + date, + + /** Float Editor */ + float, + + /** Integer Editor */ + integer, + + /** Long Text Editor */ + longText, + + /** Multiple Select Editor */ + multipleSelect, + + /** Single Select Editor */ + singleSelect, + + /** Text Editor */ + text, +} diff --git a/src/app/modules/angular-slickgrid/models/fieldType.ts b/src/app/modules/angular-slickgrid/models/fieldType.enum.ts similarity index 100% rename from src/app/modules/angular-slickgrid/models/fieldType.ts rename to src/app/modules/angular-slickgrid/models/fieldType.enum.ts diff --git a/src/app/modules/angular-slickgrid/models/filterConditionOption.interface.ts b/src/app/modules/angular-slickgrid/models/filterConditionOption.interface.ts index b410806d4..5979465ae 100644 --- a/src/app/modules/angular-slickgrid/models/filterConditionOption.interface.ts +++ b/src/app/modules/angular-slickgrid/models/filterConditionOption.interface.ts @@ -1,4 +1,4 @@ -import { FieldType } from './fieldType'; +import { FieldType } from './fieldType.enum'; export interface FilterConditionOption { operator: string; diff --git a/src/app/modules/angular-slickgrid/models/filterType.ts b/src/app/modules/angular-slickgrid/models/filterType.enum.ts similarity index 100% rename from src/app/modules/angular-slickgrid/models/filterType.ts rename to src/app/modules/angular-slickgrid/models/filterType.enum.ts diff --git a/src/app/modules/angular-slickgrid/models/index.ts b/src/app/modules/angular-slickgrid/models/index.ts index 105508d36..114e0a554 100644 --- a/src/app/modules/angular-slickgrid/models/index.ts +++ b/src/app/modules/angular-slickgrid/models/index.ts @@ -11,6 +11,7 @@ export * from './checkboxSelector.interface'; export * from './collectionFilterBy.interface'; export * from './collectionSortBy.interface'; export * from './column.interface'; +export * from './columnEditor.interface'; export * from './columnFilter.interface'; export * from './columnFilters.interface'; export * from './columnPicker.interface'; @@ -21,8 +22,9 @@ export * from './currentSorter.interface'; export * from './delimiterType.enum'; export * from './editCommand.interface'; export * from './editor.interface'; +export * from './editorType.enum'; export * from './exportOption.interface'; -export * from './fieldType'; +export * from './fieldType.enum'; export * from './fileType.enum'; export * from './filter.interface'; export * from './filterArguments.interface'; @@ -30,7 +32,7 @@ export * from './filterCallback.interface'; export * from './filterChangedArgs.interface'; export * from './filterCondition.interface'; export * from './filterConditionOption.interface'; -export * from './filterType'; +export * from './filterType.enum'; export * from './formatter.interface'; export * from './graphqlDatasetFilter.interface'; export * from './graphqlCursorPaginationOption.interface'; diff --git a/src/app/modules/angular-slickgrid/sorters/sorterUtilities.ts b/src/app/modules/angular-slickgrid/sorters/sorterUtilities.ts index f99386cd8..b0d60b280 100644 --- a/src/app/modules/angular-slickgrid/sorters/sorterUtilities.ts +++ b/src/app/modules/angular-slickgrid/sorters/sorterUtilities.ts @@ -1,4 +1,4 @@ -import { FieldType } from './../models/fieldType'; +import { FieldType } from './../models/index'; import { Sorters } from './index'; export function sortByFieldType(value1: any, value2: any, fieldType: FieldType, sortDirection: number) {