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

Dropdown with default value from async request array

1 Answer 939 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mihai
Top achievements
Rank 1
Mihai asked on 19 Mar 2019, 02:07 AM

Hello,

We are fetching records from server and creating a dropdown list and would like to set the first item in that list as the default selected item in the dropdown. The example in the documentation only shows a hardcoded list with a "Select sport..." default item.We tried to set the default item to the first element in the async list, but the first element will show up twice in the dropdown! Please help:

 

import React from 'react';
import ReactDOM from 'react-dom';
import { DropDownList } from '@progress/kendo-react-dropdowns';

class AppComponent extends React.Component {
    sports = [ 'Basketball', 'Football', 'Tennis', 'Volleyball' ];

    render() {
              return (
                    <DropDownList
                          data={this.sports}
                           defaultItem={this.sports[0]}
                    />
);
}
}

ReactDOM.render(
<AppComponent />,
document.querySelector('my-app')
);

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Mar 2019, 09:09 AM
Hello, Mihai,

The default item is closer to functionality as the placeholder.

If this has to be an actual item I can suggest setting it to the defaultValue or the value property depending if the DropDown is in controlled or uncontrolled mode:

https://stackblitz.com/edit/react-scuuez?file=app/main.js

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
Mihai
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or