From 2ee03b08ec895d8dd9bac674409f1b5e9583df84 Mon Sep 17 00:00:00 2001 From: Jeremy Zagorski Date: Tue, 15 May 2018 22:09:40 -0400 Subject: [PATCH 1/3] fix(editors): fix serialization/deserilization in editors dateEditor was serializing/deserializing wrong value. Also need to check for empty date value because moment will throw an error. `singleSelect` and `multipleSelectEditor` were serializing the actual value (e.g number type) when it should be serializing to a string and `applyValue` should be deserializing from string to actual type (e.g. number). closes #56 --- .../src/aurelia-slickgrid/editors/dateEditor.ts | 12 ++++++++++-- .../editors/multipleSelectEditor.ts | 6 ++++-- .../aurelia-slickgrid/editors/singleSelectEditor.ts | 8 +++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts index b06dc563c..ab29b0aaf 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts @@ -91,14 +91,22 @@ export class DateEditor implements Editor { } serializeValue() { + const domValue: string = this.$input.val(); + + if (!domValue) return ''; + const outputFormat = mapMomentDateFormatWithFieldType(this.args.column.type || FieldType.dateIso); - const value = moment(this.defaultDate).format(outputFormat); + const value = moment(domValue).format(outputFormat); return value; } applyValue(item: any, state: any) { - item[this.args.column.field] = state; + if (!state) return; + + const outputFormat = mapMomentDateFormatWithFieldType(this.args.column.type || FieldType.dateIso); + + item[this.args.column.field] = moment(state, outputFormat).toDate(); } isValueChanged() { diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts index aa37d3fbc..f3a3464f3 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts @@ -118,7 +118,9 @@ export class MultipleSelectEditor implements Editor { } applyValue(item: any, state: any): void { - item[this.args.column.field] = state; + item[this.args.column.field] = this.collection + .filter(c => state.indexOf(c[this.valueName].toString()) !== -1) + .map(c => c[this.valueName]); } destroy() { @@ -141,7 +143,7 @@ export class MultipleSelectEditor implements Editor { } serializeValue(): any { - return this.currentValues; + return this.$editorElm.val(); } focus() { diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts index bed47e619..f1c5e8fcd 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts @@ -110,7 +110,8 @@ export class SingleSelectEditor implements Editor { } applyValue(item: any, state: any): void { - item[this.args.column.field] = state; + item[this.args.column.field] = findOrDefault(this.collection, (c: any) => + c[this.valueName].toString() === state)[this.valueName]; } destroy() { @@ -119,7 +120,8 @@ export class SingleSelectEditor implements Editor { loadValue(item: any): void { // convert to string because that is how the DOM will return these values - this.defaultValue = item[this.columnDef.field].toString(); + // make sure the prop exists first + this.defaultValue = item[this.columnDef.field] && item[this.columnDef.field].toString(); this.$editorElm.find('option').each((i: number, $e: any) => { if (this.defaultValue === $e.value) { @@ -133,7 +135,7 @@ export class SingleSelectEditor implements Editor { } serializeValue(): any { - return this.currentValue; + return this.$editorElm.val(); } focus() { From 016f070fafc859e05f3dbdafdc477d1a531922f7 Mon Sep 17 00:00:00 2001 From: Jeremy Zagorski Date: Tue, 15 May 2018 22:50:41 -0400 Subject: [PATCH 2/3] refactor(editors): serialize select editors to actual type not sure why i thought I should always make the serialized value a string. Probabaly because I was chaning the `dateEditor` at the same time. Anyway, the serailied value from the `valueName` property should always be a simple type. --- .../src/aurelia-slickgrid/editors/multipleSelectEditor.ts | 6 ++---- .../src/aurelia-slickgrid/editors/singleSelectEditor.ts | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts index f3a3464f3..aa37d3fbc 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/multipleSelectEditor.ts @@ -118,9 +118,7 @@ export class MultipleSelectEditor implements Editor { } applyValue(item: any, state: any): void { - item[this.args.column.field] = this.collection - .filter(c => state.indexOf(c[this.valueName].toString()) !== -1) - .map(c => c[this.valueName]); + item[this.args.column.field] = state; } destroy() { @@ -143,7 +141,7 @@ export class MultipleSelectEditor implements Editor { } serializeValue(): any { - return this.$editorElm.val(); + return this.currentValues; } focus() { diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts index f1c5e8fcd..7eb05ef19 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/singleSelectEditor.ts @@ -110,8 +110,7 @@ export class SingleSelectEditor implements Editor { } applyValue(item: any, state: any): void { - item[this.args.column.field] = findOrDefault(this.collection, (c: any) => - c[this.valueName].toString() === state)[this.valueName]; + item[this.args.column.field] = state; } destroy() { @@ -135,7 +134,7 @@ export class SingleSelectEditor implements Editor { } serializeValue(): any { - return this.$editorElm.val(); + return this.currentValue; } focus() { From 7bc8baf241a6079763e04b673ef90bb52d5f820a Mon Sep 17 00:00:00 2001 From: Jeremy Zagorski Date: Thu, 17 May 2018 14:27:45 -0400 Subject: [PATCH 3/3] refactor(editors): load defaultDate into flatpickr on loadValue this will allow the excel cell copy to work when serializing this.$input.value() --- aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts b/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts index ab29b0aaf..43ea1ece4 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/editors/dateEditor.ts @@ -88,6 +88,7 @@ export class DateEditor implements Editor { loadValue(item: any) { this.defaultDate = item[this.args.column.field]; + this.flatInstance.setDate(item[this.args.column.field]); } serializeValue() {