- Home
- Forum
- Angular - EJ 2
- Query Builder - Issue with using 2 DropdownTrees for certain conditions
Query Builder - Issue with using 2 DropdownTrees for certain conditions
Hello,
I am using the Query Builder with the fields dropdown set up as a DropdownTree list. This dropdown works as expected. When I select a field that also uses a DropdownTree through a ColumnTemplate, I am getting errors in the console and the dropdown does not load any items.
This is the error that is displayed:
And this is how we have set up our template for these fields; I have removed some of the write portion for simplicity:
lookupTemplate: TemplateColumn = {
create: () => {
return createElement('input', { attrs: { 'type': 'text' } });
},
destroy: (args: { elementId: string }) => {
let dropdown: DropDownList = (getComponent(document.getElementById(args.elementId), 'dropdownlist') as DropDownList);
let dropdowntree: DropDownTree = (getComponent(document.getElementById(args.elementId), 'dropdowntree') as DropDownTree);
let textbox: TextBox = (getComponent(document.getElementById(args.elementId), 'textbox') as TextBox);
if (dropdown) {
dropdown.destroy();
}
if (dropdowntree) {
dropdowntree.destroy();
}
if (textbox) {
textbox.destroy();
}
},
write: (args: { elements: Element, values: string[] | string, operator: string, field: string }) => {
...
this.getLookupData(type, options).subscribe(result => {
// For each result that is returned, we should pull the names and make a data array
let resultArray: any[] = result;
let parentFieldName: string = options.isHierarchy ? this.ParentFieldName : "";
// This method creates an array of items in the following format, where parentFieldName is > 0 if it is a child for a hierarchy, and 0 if it is a root/top level item:
// { value: 'value', text: 'text', id: 1, parentFieldName: 3, hasChild: true }
// The last 2 properties are only added if isHierarchy is true
let dataSource: any[] = this.createLookupArray(resultArray, type, parentFieldName);
if (options.isHierarchy) {
// Create the DropdDownTree for the hierarchy value field
let dropDownObj: DropDownTree = new DropDownTree({
fields: {
dataSource: dataSource,
parentValue: parentFieldName,
hasChildren: "hasChild"
},
allowFiltering: true,
filterType: 'StartsWith',
change: (e: any) => {
this.queryBuilder.notifyChange(e.value.length > 0 ? e.value[0] : "", e.element);
}
});
dropDownObj.appendTo('#' + args.elements.id);
} else {
let dropDownObj: DropDownList = new DropDownList({
dataSource: dataSource,
allowFiltering: true,
filterType: 'StartsWith',
value: args.values as string,
change: (e: any) => {
this.queryBuilder.notifyChange(e.itemData.value, e.element);
}
});
dropDownObj.appendTo('#' + args.elements.id);
}
});
...
}
};
Is there something wrong with the way this hierarchy dropdown is set up? Please let me know if there is anything I can fix.
Thank you,
KS
Hi KS,
We are unable to replicate the issue on our end. We have prepared a sample based on your requirements. It is working fine. Kindly refer to the below sample Link.
Sample Link: https://stackblitz.com/edit/angular-75yatm-ryn8au?file=src%2Fapp.component.ts
Note: Your Provided sample is not working properly.
If you are still facing issues, could you please replicate the issue in our sample with replication steps and a video demonstration? Based on that, we will check and provide you with a better solution quickly.
Regards,
KeerthiKaran K V
Hello,
Sorry for the delay.
I am able to replicate the behavior by using our data array in the following sample link:
https://stackblitz.com/edit/angular-75yatm-eaaezb?file=src%2Fapp.component.html,src%2Fapp.component.ts,package.json,src%2Fapp.component.css
When you select General > Assigned To, the value field is supposed to be a hierarchy dropdown. However, it is not able to load and just displays an empty dropdown when opened and there is an error in the console.
Is this an issue with our data?
Thank you,
KS
Hi KS,
We have checked and tested the shared sample on our end and were able to replicate the reported issue. Upon further validation, we identified that in the datasource you provided, "parentId" values are set as zero for some nodes. Additionally, there are no other nodes that contain "id" value as zero, leading to the reported issue.
We suggest not setting the “parentId” value as zero, if you are referring to the node as the root node, either set the “parentId” as null or ignore the "parentId" value altogether. Furthermore, just declare the another nodes with “id” value as zero inside the datasource.
Also, we noticed that you have not properly mapped the "value" field. We recommend setting the "value" field as "id." This approach is the proper way to map fields in the DropdownTree component. Please refer to below code snippet and sample.
|
var localData = [ { value: '1 - Failure', text: '1 - Failure', id: 19, //parentId: 0, hasChild: true, }, { value: '2 - Service Request', text: '2 - Service Request', id: 1, //parentId: 0, hasChild: true, }, { value: '3 - Work Request', text: '3 - Work Request', id: 20, //parentId: 0, hasChild: true, },
]; let dropDownTreeObj: DropDownTree = new DropDownTree({ fields: { dataSource: localData, parentValue: 'parentId', hasChildren: 'hasChild', text: 'text', value: 'id', }, allowFiltering: true, filterType: 'StartsWith', change: (e: any) => { this.qryBldrObj.notifyChange(e.value, e.element); }, }); dropDownTreeObj.appendTo('#' + args.elements.id); |
Sample link: https://stackblitz.com/edit/angular-75yatm-pf89ij?file=src%2Fapp.component.ts
Please let us know if you need any further assistance on this.
Regards,
KeerthiKaran K V
- 3 Replies
- 2 Participants
-
KS KS
- Sep 15, 2023 03:24 PM UTC
- Nov 17, 2023 01:56 PM UTC