The Date formatting can be achieved in ticks
and tooltip
using renderingTicks
and tooltipChange
events respectively. The process
of formatting is explained in the below sample.
import * as React from 'react';
import * as ReactDOM from "react-dom";
import { SliderComponent } from '@syncfusion/ej2-react-inputs';
export default class App extends React.Component {
constructor() {
super(...arguments);
this.min = new Date("2013-06-13").getTime();
this.max = new Date("2013-06-21").getTime();
this.step = 86400000;
this.value = new Date("2013-06-15").getTime();
// Slider ticks customization
this.ticks = { placement: "After", largeStep: 2 * 86400000 };
this.tooltip = { placement: "Before", isVisible: true };
}
renderingTicksHandler(args) {
let totalMiliSeconds = Number(args.value);
// Converting the current milliseconds to the respective date in desired format
let custom = { year: "numeric", month: "short", day: "numeric" };
args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
}
tooltipChangeHandler(args) {
let totalMiliSeconds = Number(args.text);
// Converting the current milliseconds to the respective date in desired format
let custom = { year: "numeric", month: "short", day: "numeric" };
args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
}
render() {
return (<div id="container">
<div className="wrap">
<SliderComponent id="slider" min={this.min} max={this.max} value={this.value} step={this.step} tooltip={this.tooltip} ticks={this.ticks} showButtons={true} tooltipChange={this.tooltipChangeHandler.bind(this)} renderingTicks={this.renderingTicksHandler.bind(this)}/>
</div>
</div>);
}
}
ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React ListView</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/20.1.58/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.58/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.58/ej2-react-popups/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.58/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="index.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>
</body>
</html>
.sliderwrap {
margin-top: 20px;
}
.sliderwrap label {
font-size: 13px;
font-weight: 100;
margin-top: 15px;
padding-bottom: 15px;
}
.wrap {
box-sizing: border-box;
height: 100px;
margin: 0 auto;
padding: 30px 10px;
width: 460px;
}
.wrap .label {
text-align: center;
}
.labeltext {
text-align: center;
}
import * as React from 'react';
import * as ReactDOM from "react-dom";
import { SliderComponent } from '@syncfusion/ej2-react-inputs';
export default class App extends React.Component<{}, {}> {
public min = new Date("2013-06-13").getTime();
public max = new Date("2013-06-21").getTime();
public step = 86400000;
public value = new Date("2013-06-15").getTime();
// Slider ticks customization
public ticks: TicksDataModel = { placement: "After", largeStep: 2 * 86400000 };
public tooltip: TooltipDataModel = { placement: "Before", isVisible: true };
renderingTicksHandler(args: SliderTickEventArgs) {
let totalMiliSeconds = Number(args.value);
// Converting the current milliseconds to the respective date in desired format
let custom = { year: "numeric", month: "short", day: "numeric" };
args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
}
tooltipChangeHandler(args: SliderTooltipEventArgs) {
let totalMiliSeconds = Number(args.text);
// Converting the current milliseconds to the respective date in desired format
let custom = { year: "numeric", month: "short", day: "numeric" };
args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
}
render() {
return (
<div id="container">
<div className="wrap">
<SliderComponent
id="slider"
min={this.min}
max={this.max}
value={this.value}
step={this.step}
tooltip={this.tooltip}
ticks={this.ticks}
showButtons={true}
tooltipChange={this.tooltipChangeHandler.bind(this) as any}
renderingTicks={this.renderingTicksHandler.bind(this) as any}
/>
</div>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('element'));