Material-ui: [DatePicker] Display week numbers

Created on 19 Jul 2018  路  6Comments  路  Source: mui-org/material-ui

I would like to have the possibility to display week numbers in the picker. Maybe as the first column before the first day of the week. Something like this would fit my needs:

Capture d鈥檈虂cran 2020-04-12 a虁 22 24 36

https://jqueryui.com/datepicker/#show-week

Capture d鈥檈虂cran 2020-04-12 a虁 22 21 14

http://react-day-picker.js.org/examples/customization-week-numbers

Capture d鈥檈虂cran 2020-04-12 a虁 22 21 54

https://reactdatepicker.com/#example-display-week-numbers

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| @material-ui/lab | v5.0.0-alpha.16 |

DatePicker enhancement

Most helpful comment

In case someone is running into this requirement.

As suggested I used a custom dayRenderer with an absolute positioned div.

renderDay(date, selectedDate, dayInCurrentMonth) {
    return (
        <div>
            {date.day() === 0 && <div className={'week'}>{date.isoWeek()}</div>}
            <Day
                current={date.isSame(moment(), 'day')}
                hidden={!dayInCurrentMonth}
                selected={date.isSame(selectedDate, 'day')}
            >
                {date.date()}
            </Day>
        </div>
    );
}

and

.week {
    position: absolute;
    font-size: 0.6em;
    color: red;
}

All 6 comments

Actually it so unpopular issue - so I think we will not integrate it as part of the library. I can imagine only one workaround. You can create your own renderer of day and check if - this is the first day of week - show the number of week at the left

In case someone is running into this requirement.

As suggested I used a custom dayRenderer with an absolute positioned div.

renderDay(date, selectedDate, dayInCurrentMonth) {
    return (
        <div>
            {date.day() === 0 && <div className={'week'}>{date.isoWeek()}</div>}
            <Day
                current={date.isSame(moment(), 'day')}
                hidden={!dayInCurrentMonth}
                selected={date.isSame(selectedDate, 'day')}
            >
                {date.date()}
            </Day>
        </div>
    );
}

and

.week {
    position: absolute;
    font-size: 0.6em;
    color: red;
}

@oliviertassinari I want to start looking into adding this feature.
Are there design / UX guidelines here for this matter?

@dvh91 Could you explore on what's missing from the current customization API to have this working :)?

@oliviertassinari If we going in the path of allowing it as API and not a proper feature of the library, then renderCalendarWeek or renderCalendar along with renderCalendarHeader (the row with the weekday names as it's sticky and not part of the Calendar component) should be enough.

@dvh91 From my perspective, a prop to display the week number could be interesting. The alternative would be to improve the customization API to allow it, a demo in the documentation would be great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanflorence picture ryanflorence  路  3Comments

sys13 picture sys13  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

FranBran picture FranBran  路  3Comments

reflog picture reflog  路  3Comments