All Components

Integration with JSON

Generally, the data which is received from the server is serialized in a JSON format.

The date object in JSON is an ISO8601-formatted date string. On the other hand, the Calendar works only with JavaScript Date instances.

To bind the Calendar to dates which are serialized as strings, handle the parsing process:

  1. Convert the JSON date strings into valid JavaScript Date objects by using the IntlService or any other suitable Date parser.
  2. Define the value property of the component.
  3. Wire the onChange property of the Calendar to get the selected Date value.

The following example demonstrates how to set the value of the Calendar.

import { provideIntlService } from '@progress/kendo-react-intl';

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};

        // Simulate data retrieval from the server.
        setTimeout(() => {
            const date = '2016-01-04';
            this.setState({ value: provideIntlService(this).parseDate(date) });
        }, 1000);
    }

    render() {
        return <Calendar value={this.state.value} onChange={this.onChange} />;
    }

    onChange = (event) => {
        this.setState({ value: event.value });
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);
In this article