shinyWidgets
shinyWidgets copied to clipboard
Add functionality to pass `onRenderCell` JS function to air datepicker
It would be very useful to me to be able to pass a onRenderCell
JS function to the timepickerOpts
of an airDatepickerInput
.
Slightly adapted from the air datepicker documentation on onRenderCell
, the following code would be quite nice to color the cells on some logic, in this case an ugly chessboard.
onRenderCell({ date, cellType }) {
if (date.getDate() % 2) {
return { classes: "CLASSGREEN" };
} else {
return { classes: "CLASSRED" };
}
}
Which we could then color with css like this
.CLASSRED { background: red; }
.CLASSGREEN { background: green; }
resulting in something like this:
So far I didn't find an option to provide the function to the airDatepickerInput
from R shiny.
Using plain javascript, I would use it like so:
// index.html
...
<body>
...
<input type="text" id="el" />
<script src="src/index.js"></script>
</body>
// index.js
import AirDatepicker from "air-datepicker";
import en from "air-datepicker/locale/en";
import "air-datepicker/air-datepicker.css";
new AirDatepicker("#input_id", {
onRenderCell({ date, cellType }) {
if (date.getDate() % 2) {
return { classes: "CLASSGREEN" };
} else {
return { classes: "CLASSRED" };
}
},
locale: en,
inline: true
});
Is this possible at the moment and I overlooked a solution? If not, how complicated is it to pass this along and can I help in any way? Otherwise, thanks for the wonderful package!
Hello,
Currently no that's not possible. The two reasons are:
-
onRenderCell
is already used (here), but we can use this only if noonRenderCell
is provided - we can only pass option as character in JSON (no javascript), so we'll need to evaluate afterwards what is passed, there's some methods, nothing standards
Some other notes:
- shinyWidget still use previous realease of airdatepicker (v2.2.3)
- i'd like to convert all javascript bindings to use {packer}
Victor