This is a migrated thread and some comments may be shown as answers.

Combobox testfield

3 Answers 73 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sarthak
Top achievements
Rank 1
Veteran
Sarthak asked on 09 Nov 2020, 09:30 AM
I want to concat two properties to be displayed in the text field.suppose I have first-name and lastname property present in my object and I want to display something like textField=firstName+'  '+ lastName.how do I achieve this with combobox textField.

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 10 Nov 2020, 09:53 AM

Hi Sarthak,

The most straight forward solution is to map the bound collection, e.g.:

public listItems: any = [
    { firstName: "John", lastName: "Deer", value: 1 },
    { firstName: "Martin", lastName: "Duncan", value: 2 }
  ];

  ngAfterViewInit() {
    this.listItems = this.listItems.map(item => {
      return {
        firstName: `${item.firstName} ${item.lastName}`,
        value: item.value
      };
    });
  }

Here is an example:

https://stackblitz.com/edit/angular-9cci51

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Sarthak
Top achievements
Rank 1
Veteran
answered on 10 Nov 2020, 10:12 AM

So there's no way we can achieve this directly in the html?

I was reluctant to mutate the actual collection.

0
Martin
Telerik team
answered on 11 Nov 2020, 10:33 AM

Hi Sarthak,

I understand that this might be disappointing for you, but the textiField and valueField properties by default accept a string as a value and cannot include a combination of two fields. 

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ComboBox
Asked by
Sarthak
Top achievements
Rank 1
Veteran
Answers by
Martin
Telerik team
Sarthak
Top achievements
Rank 1
Veteran
Share this question
or