Search results

Getting started

This section explains you the steps required to create a simple DateRangePicker and demonstrate the basic usage of the DateRangePicker component.

Dependencies

The below list of dependencies are required to use the DateRangePicker component in your application.

|-- @syncfusion/ej2-react-calendars
  |-- @syncfusion/ej2-base
  |-- @syncfusion/ej2-react-base
  |-- @syncfusion/ej2-data
  |-- @syncfusion/ej2-calendars
  |-- @syncfusion/ej2-inputs
    |-- @syncfusion/ej2-splitbuttons
  |-- @syncfusion/ej2-lists
  |-- @syncfusion/ej2-popups
    |-- @syncfusion/ej2-buttons

Installation and configuration

You can use create-react-app to setup the applications. To install create-react-app run the following command.

npm install -g create-react-app
  • To setup basic React sample use following commands.
create-react-app quickstart --scripts-version=react-scripts-ts

cd quickstart

Adding Syncfusion packages

All the available Essential JS 2 packages are published in npmjs.com public registry. You can choose the component that you want to install. For this application, we are going to use DateRangePicker component.

To install DateRangePicker component, use the following command

npm install @syncfusion/ej2-react-calendars –save

Adding Style sheet to the Application

To render the DateRangePicker component, need to import DateRangePicker and its dependent component’s styles as given below in App.css.

@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-react-calendars/styles/material.css";

Note: If you want to refer the combined component styles, please make use of our CRG (Custom Resource Generator) in your application.

Adding DateRangePicker component to the Application

  • To include the DateRangePicker component in application import the DateRangePickerComponent from ej2-react-calendars package in App.tsx.

  • Then add the DateRangePicker component as shown in below code example.

[src/App.tsx]

import * as React from "react";
import './App.css';
//import the daterangepicker Component
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';

export default class App extends React.Component<{}, {}> {
    render() {
        return <DateRangePickerComponent id="daterangepicker" />
    }
};

Run the application

Now run the npm start command in the console, it will run your application and open the browser window.

npm start

The below examples shows the basic DateRangePicker component.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';

class App extends React.Component<{}, {}> {
    render() {
        return <DateRangePickerComponent id="daterangepicker" placeholder='Select a range' />
    }
};
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React DateRangePicker</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-lists/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>

Setting the start and end date in a range

The start and end date in a range can be defined with help of startDate and endDate property. The following example demonstrates, how to set the start date, end date on initializing the DateRangePicker.

Source
Preview
index.tsx
index.html
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DateRangePickerComponent } from '@syncfusion/ej2-react-calendars';

class App extends React.Component<{}, {}> {

    private start:Date= new Date("10/7/2017");
    private end:Date= new Date("11/15/2017");

    render() {
        return <DateRangePickerComponent id="daterangepicker" placeholder='Select a range' startDate={this.start} endDate={this.end} />
    }
};
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React DateRangePicker</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-lists/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-calendars/styles/material.css" rel="stylesheet" />
    <link href="styles.css" rel="stylesheet" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div>
    </div>
</body>

</html>