Skip to content

Commit

Permalink
fix(editors): use indexOf in multiple select editor to load value
Browse files Browse the repository at this point in the history
Merge pull request #50 from ghiscoding/fix/multiple_select_editor_indexof
  • Loading branch information
jmzagorski authored May 15, 2018
2 parents 0be30fd + b0c9815 commit 21215c4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class MultipleSelectEditor implements Editor {
}

// user might want to sort the collection
if (this.gridOptions && this.gridOptions.params && this.columnDef.params.collectionSortBy) {
if (this.columnDef.params && this.columnDef.params.collectionSortBy) {
const sortBy = this.columnDef.params.collectionSortBy;
newCollection = this.collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel);
}
Expand All @@ -130,7 +130,7 @@ export class MultipleSelectEditor implements Editor {
this.defaultValue = item[this.columnDef.field].map((i: any) => i.toString());

this.$editorElm.find('option').each((i: number, $e: any) => {
if (this.defaultValue === $e.value) {
if (this.defaultValue.indexOf($e.value) !== -1) {
$e.selected = true;
} else {
$e.selected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class SingleSelectEditor implements Editor {
}

// user might want to sort the collection
if (this.gridOptions.params && this.columnDef.params.collectionSortBy) {
if (this.columnDef.params && this.columnDef.params.collectionSortBy) {
const sortBy = this.columnDef.params.collectionSortBy;
newCollection = this.collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MultipleSelectFilter implements Filter {
}

// user might want to sort the collection
if (this.gridOptions.params && this.columnDef.filter.collectionSortBy) {
if (this.columnDef.filter && this.columnDef.filter.collectionSortBy) {
const sortBy = this.columnDef.filter.collectionSortBy;
newCollection = this.collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class SingleSelectFilter implements Filter {
}

// user might want to sort the collection
if (this.gridOptions.params && this.columnDef.filter.collectionSortBy) {
if (this.columnDef.filter && this.columnDef.filter.collectionSortBy) {
const sortBy = this.columnDef.filter.collectionSortBy;
newCollection = this.collectionService.sortCollection(newCollection, sortBy, this.enableTranslateLabel);
}
Expand Down
3 changes: 2 additions & 1 deletion aurelia-slickgrid/src/examples/slickgrid/example12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export class Example12 {
filter: {
collection: [{ value: '', label: '' }, { value: 'TRUE', labelKey: 'TRUE' }, { value: 'FALSE', labelKey: 'FALSE' }],
collectionSortBy: {
property: 'labelKey' // will sort by translated value since "enableTranslateLabel" is true
property: 'labelKey', // will sort by translated value since "enableTranslateLabel" is true
sortDesc: true
},
type: FilterType.singleSelect,
enableTranslateLabel: true,
Expand Down
4 changes: 2 additions & 2 deletions aurelia-slickgrid/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Example3 {
type: FieldType.string,
editor: Editors.multipleSelect,
params: {
collection: Array.from(Array(10).keys()).map(k => ({ value: `Task ${k}`, label: `Task ${k}` })),
collection: Array.from(Array(12).keys()).map(k => ({ value: `Task ${k}`, label: `Task ${k}` })),
collectionSortBy: {
property: 'label',
sortDesc: true
Expand Down Expand Up @@ -217,7 +217,7 @@ export class Example3 {
start: new Date(randomYear, randomMonth, randomDay),
finish: new Date(randomYear, (randomMonth + 1), randomDay),
effortDriven: (i % 5 === 0),
prerequisites: (i % 5 === 0) && i > 0 ? [`Task ${i}`, `Task ${i - 1}`] : []
prerequisites: (i % 2 === 0) && i !== 0 && i < 12 ? [`Task ${i}`, `Task ${i - 1}`] : []
};
}
this.dataset = mockedDataset;
Expand Down
5 changes: 5 additions & 0 deletions aurelia-slickgrid/src/examples/slickgrid/example4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export class Example4 {
filterable: true,
filter: {
collection: multiSelectFilterArray,
collectionSortBy: {
property: 'value',
sortDesc: true,
fieldType: FieldType.number
},
type: FilterType.multipleSelect,
searchTerms: [1, 33, 50], // default selection
// we could add certain option(s) to the "multiple-select" plugin
Expand Down

0 comments on commit 21215c4

Please sign in to comment.