Skip to content
Snippets Groups Projects
Commit ced2ebb7 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #14810 TIME 0:30 fix select search in opt

parent 1e06d556
No related branches found
No related tags found
No related merge requests found
...@@ -177,7 +177,7 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView ...@@ -177,7 +177,7 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView
let group = ''; let group = '';
let index = 1; let index = 1;
this.datasClone = JSON.parse(JSON.stringify(this.datas)); this.datasClone = JSON.parse(JSON.stringify(this.datas));
this.datasClone.forEach((element: any) => { this.datasClone.forEach((element: any, index: number) => {
if (element.isTitle) { if (element.isTitle) {
group = `group_${index}`; group = `group_${index}`;
element.id = group; element.id = group;
...@@ -198,30 +198,24 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView ...@@ -198,30 +198,24 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView
// To resfresh filteredDatas if data is modfied // To resfresh filteredDatas if data is modfied
ngDoCheck(): void { ngDoCheck(): void {
if (JSON.stringify(this.datas) !== JSON.stringify(this.datasClone) && !this.isModelModified) { if (this.datasClone.length !== this.datas.length || this.datasClone.length === 0 && this.isModelModified) {
this.isModelModified = true;
this.datasClone = JSON.parse(JSON.stringify(this.datas)); this.datasClone = JSON.parse(JSON.stringify(this.datas));
let group = '';
// if more data => contruct title again let index = 1;
if (this.datasClone.length !== this.datas.length) { this.datasClone.forEach((element: any) => {
let group = ''; if (element.isTitle) {
let index = 1; group = `group_${index}`;
this.datasClone.forEach((element: any) => { element.id = group;
if (element.isTitle) { index++;
group = `group_${index}`; } else {
element.id = group; element.group = group;
index++; }
} else { });
element.group = group;
}
});
}
this.filteredDatas = this.formControlSearch.valueChanges this.filteredDatas = this.formControlSearch.valueChanges
.pipe( .pipe(
startWith(''), startWith(''),
map(value => this._filter(value)) map(value => this._filter(value))
); );
this.isModelModified = false; this.isModelModified = false;
} }
} }
...@@ -400,9 +394,9 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView ...@@ -400,9 +394,9 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView
} else if (typeof value === 'string' && value !== '') { } else if (typeof value === 'string' && value !== '') {
const filterValue = this.latinisePipe.transform(value.toLowerCase()); const filterValue = this.latinisePipe.transform(value.toLowerCase());
const group = this.datas.filter((option: any) => option['isTitle'] && this.latinisePipe.transform(option['label'].toLowerCase()).includes(filterValue)).map((opt: any) => opt.id); const group = this.datasClone.filter((option: any) => option['isTitle'] && this.latinisePipe.transform(option['label'].toLowerCase()).includes(filterValue)).map((opt: any) => opt.id);
return this.datas.filter((option: any) => (option['isTitle'] && group.indexOf(option['id']) > -1) || (group.indexOf(option['group']) > -1 || this.latinisePipe.transform(option['label'].toLowerCase()).includes(filterValue))); return this.datasClone.filter((option: any) => (option['isTitle'] && group.indexOf(option['id']) > -1) || (group.indexOf(option['group']) > -1 || this.latinisePipe.transform(option['label'].toLowerCase()).includes(filterValue)));
} else { } else {
return this.datas; return this.datas;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment