I have a column in a treegrid made up of ids. The ids are guids and I don't want to display them to the user. Instead I want to display the user friendly text that maps to the id.
When the user edits the row I show an autocomplete that has a list of friendly ids that the user can choose from.
I'm having an issue setting the autocomplete value. Instead of setting the user friendly text, it is showing the the value (which would be a guid) inse
|
public accountGroupFields: Object = { groupBy: 'group', value: 'text' };
write: (args: { rowData: Object, column: Column }) => {
this.accountAutoComplete = new AutoComplete();
this.accountAutoComplete.dataSource = this.accountAutoCompleteData;
this.writeValue = (args.rowData as TreeGridRowData).text;
this.accountAutoComplete.value = this.writeValue;
} |
|
export class TreeGridRowData {
id: string;
text: string;
} |
|
export let treeGridData: TreeGridRowData[] = [
{
id:"5",
text:"Id One text",
},
{
id:"1",
text:"Id Two text",
},
{
id:"3",
text:"Id Three text",
}
]; |
Thanks Berly,
I'll give this a try and see how far I get.
1) Do you have any guidance on how to handle duplicate values with different ids? I have some ideas, but I was curious to get your take.
2) I started experimenting with duplicate values and getting the id on the change and select events. I notice that the wrong item is returned in itemdata for these. it looks like it is returning the first match. I worked around this by grabbing the id from the item field. Wanted to bring it to the teams attention as a potential bug.
Selecting the last item on the list is returning the object for the 2nd to last.
|
import { AutoComplete, ComboBox,FilteringEventArgs, PopupEventArgs } from "@syncfusion/ej2-angular-dropdowns";
import { Column } from "@syncfusion/ej2-angular-treegrid";
import { Predicate, Query } from "@syncfusion/ej2-data";
import { AutoCompleteData } from "./autocompletedata";
import { IdToTextMapper } from "./id-to-text-mapper";
import { TreeGridRowData } from "./TreeGridRowData";
export class AccountDropdownLogic {
public accountIdMapper: IdToTextMapper;
public accountEditOptions: Object;
public accountAutoComplete: ComboBox;
public accountElement: HTMLElement;
public accountAutoCompleteData: any = [];
public accountGroupFields: Object = { groupBy: 'group', text: 'text', value:'id' };
public writeValue: string;
constructor() {
this.accountEditOptions = {
create: () => {
this.accountElement = document.createElement('input');
return this.accountElement;
},
read: () => {
return this.accountAutoComplete.value;
},
destroy: () => {
this.accountAutoComplete.destroy();
},
write: (args: { rowData: Object, column: Column }) => {
this.accountAutoComplete = new ComboBox();
this.accountAutoComplete.dataSource = this.accountAutoCompleteData;
this.writeValue = (args.rowData as TreeGridRowData).text;
this.accountAutoComplete.value = this.writeValue;
// this.accountAutoComplete.text=this.accountIdMapper.getText(this.writeValue);
this.accountAutoComplete.showClearButton = true;
this.accountAutoComplete.popupWidth = "300px";
// this.accountAutoComplete.showPopupButton = true;
this.accountAutoComplete.appendTo(this.accountElement);
this.accountAutoComplete.fields = this.accountGroupFields;
this.accountAutoComplete.cssClass = "autocomplete";
|
Thanks Berly, but I can't use the combobox, because it does not support autocomplete typing.
|
write: (args: { rowData: Object, column: Column }) => {
this.accountAutoComplete = new ComboBox();
this.accountAutoComplete.dataSource = this.accountAutoCompleteData;
this.writeValue = (args.rowData as TreeGridRowData).text;
this.accountAutoComplete.value = this.writeValue;
// this.accountAutoComplete.text=this.accountIdMapper.getText(this.writeValue);
this.accountAutoComplete.showClearButton = true;
this.accountAutoComplete.allowFiltering = true;
...
} |
Thanks for pointing this out. I did not realize that the Combobox had this type of functionality.
I see that when I set the value field for the combobox it still updates the display text to the ID and not the text.
In the example below where I have duplicate text in two different groups. How can I make sure the right item gets selected when the user pulls down the dropdown?
For example if the value field = 77 and I set the text then the user will see the text under the wrong group selected which will be confusing for them.
I believe I have this working now.
I attached a sample in case anyone else runs into a similar problem.
1) I switched to use the combobox
2) I assign text in the write event
3) I assign the value in the databound event.
4) I have to save the value on the change event and the write event to return in the read event.
Doing this allows for the right item to be selected in the combobox dropdown.
Thank you for your help on this one. Supporting duplicate combobox values is critical to my applications functionality.