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

DropdownList - binding textField attribute to inner value of json object

3 Answers 397 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 10 Jul 2018, 09:02 AM

I have problem with textField binding to value. My JSON looks like this and I need to bind name.value to textField attribute, but as it is shown below, its not working. How I can manage that?

{
  "id":"some_Id",

  "code":"some_code",
  "name":{
        "value": "Czech republic",
        "translations": []
   },
   etc....
}

<DropDownList
    data={this.props.headerData}
    textField={"name.value"}
    valueField={"id"}
    value={this.props.selectedImporter.id}
    className="dd-header"
    onChange={this.importerContextChanged} />
);

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 11 Jul 2018, 08:21 AM
Hello, Martin,

Thank you for the details.

Currently, the DropDown is working only with flat data structures.

In this case, I can suggest setting the data as a function which will take the data to make a flat textField property based on the nested structure and return the modified data:

flatData = (data) => {
    data.map(item => {item.textField = item.name.value})
    return data
}

<DropDownList
    data={this.flatData(this.data)}
    textField={'textField'}

I made an example demonstrating this:

https://next.plnkr.co/edit/dU57ZYEYOuYmFLjb

As we can agree that it will be beneficial to support this out of the box, we will discuss this enhancement of the component.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Martin
Top achievements
Rank 1
answered on 11 Jul 2018, 09:39 AM

Hi,

yeah this is great example, didn't even think about it, it could be done like this. Thanks a lot.

Best regards,
Martin

0
Stefan
Telerik team
answered on 11 Jul 2018, 10:31 AM
Hello, Martin,

I'm glad to hear that this is helpful.

We also agreed to log the enhancement which will eliminate the need to flat the data.

You can track its progress at:

https://github.com/telerik/kendo-react/issues/46

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Martin
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Martin
Top achievements
Rank 1
Share this question
or