Home > OS >  how to get selected ranges type from datepicker antd
how to get selected ranges type from datepicker antd

Time:12-20

I have display all the field for the ranges

onCalendarChange={onCalendarChange}
        onChange={onChangeDate}
        onOpenChange={handleOpenChange}
        open={forceOpen}
        placeholder={PLACEHOLDER}
        ranges={ranges}
        ref={pickerRef}
        separator="-"
        size="small"
        value={value}

**My Question is : how to get the selected range from antd date picker.

I have tried to onOK and onPanelChnages but I didnt find the way to get slected ranges type as string .

CodePudding user response:

https://ant.design/components/date-picker#rangepicker

according to official docs, you can use onChange

onChange={(dates, dateString)=> console.log(dates, dateString)}

CodePudding user response:

Use this hope it will solve your issue

const onCalendarChange = (dates, dateStrings) => {
   console.log(dates);  // this will contain the selected range (start date 
   and end date)
   console.log(dateStrings);  // this will contain the selected range as 
   strings (e.g. "2022-12-20 - 2022-12-30")
};

<DatePicker
 onCalendarChange={onCalendarChange}
  ranges={ranges}
   ...
 />
  • Related