DateTime display() as an option
DateTime display() as an option
Loren Maxwell
Posts: 474Questions: 114Answers: 10
For the DateTime plugin, display() is available through the api, but an option would be helpful as well.
{
label: 'Some date field',
name: 'some_date',
type: 'datetime',
opts: {
display: {
year: 1982,
month: 10
}
}
},
or maybe...
{
label: 'Some date field',
name: 'some_date',
type: 'datetime',
opts: {
display: [1982, 10]
}
},
The display option would probably only take affect if there is no current value or default value set.
This question has accepted answers - jump to:
Answers
Good idea! Added to the list
.
Allan
@allan -- just curious as to if this might be in the next version (1.6.2 or 1.7) of
datetime.I have several pages that represent years and Editors for the tables on those pages.
I don't want to set a default value because some of the dates will be unknown, but I'd like the calendar to be ready with the year set based on the page.
Otherwise changing the year on the calendar from 2025 to 1982 or whatever adds a couple of clicks and a scroll through the years for each entry.
I've tried to approach it this way:
However the calendar reverts back to the current date (and the2025 year) on
editor.val('game_date', '').Should I approach it differently? Or will you have the update done soon anyway?
I hope so, but can't say for certain while it will be done. I'm currently focused on a major update in DataTables core.
I don't know that there is a better option that getting it implemented I'm afraid.
Allan
Ok, thanks -- and thanks for all the great support!
Its been a funny old day here, so rather than trying to do a long period of focused work, I've been doing little bits and thought I'd look at this.
I was midway through writing a reply saying it would be a bit tricky to do, when inspiration hit! I've just made this commit to add support for a
displayoption on initialisation. Now if the field doesn't have a value then the picker will show that month / year. If it does have a value, then it displays that month / year of course.This is the option I went for:
to match the
display()return. Both properties are required.Allan
YAY! Looking forward to the release!
Tiny improvements like this have HUGE impacts when doing hundreds or thousands of repetitive entries!
Morning @allan -- any estimate when this latest version might be available through the CDN?
No other immediate plans for changes in DateTime, so that's 1.6.2 tagged up and released. Thanks for the nudge.
Allan
Thanks, @allan!
And this works exactly as requested!
But... this is one of those times that after getting what I asked for I then realized it wasn't actually what I wanted
In hindsight, what I really want is a way to call this: https://datatables.net/extensions/datetime/api/display()
when using
DateTime, but I don't see where that's possible.Basically I have two controls on my Editor form, one for the year of a game (
season_code) and one for the specific date of that game (game_date).I'd like the
game_date(aDateTime) to update when theseason_codechanges.Something like:
Try adding:
before you initialise the Editor. Then you should be able to do:
i.e.
inst()will get the DateTime picker instance so you can work with its API.Allan
Thanks, @allan! Works like a charm!
Sorry for not realizing ahead of time that's what I was looking for, but hopefully someone else will find the
display()option useful!No worries. It makes a lot of sense to have it!
Allan
After some use, I think this should be included as part of the basic DateTime editor field for others who might want to set the display based on other fields:
Or even better a method to call
display()directly:I've actually committed it already
. It will be in the nest release!
Allan
Awesome! Thanks, @allan!