DateTime Editor
Combined date and time editor with calendar and time picker.
The DateTimeEditor combines date and time selection in a single editor, providing both calendar and time picker controls.
Basic Usage
const columns: ColumnDef[] = [ { field: 'createdAt', header: 'Created At', editor: 'datetime' }];Editor Options
interface DateTimeEditorOptions { dateFormat?: string; // Default: 'YYYY-MM-DD' timeFormat?: '12h' | '24h'; // Default: '24h' showSeconds?: boolean; placeholder?: string; className?: string; theme?: 'light' | 'dark' | 'auto'; autoFocus?: boolean; required?: boolean; minDate?: string; maxDate?: string; commitOnBlur?: boolean; closeOnScroll?: boolean; validator?: (value: string) => boolean | string;}Date and Time Formats
Date Format
// ISO format (default){ editor: 'datetime', editorOptions: { dateFormat: 'YYYY-MM-DD' // 2024-12-23 14:30 }}
// US format{ editor: 'datetime', editorOptions: { dateFormat: 'MM/DD/YYYY' // 12/23/2024 2:30 PM }}
// European format{ editor: 'datetime', editorOptions: { dateFormat: 'DD/MM/YYYY' // 23/12/2024 14:30 }}Time Format
// 24-hour format{ editor: 'datetime', editorOptions: { timeFormat: '24h' // 14:30 }}
// 12-hour format with AM/PM{ editor: 'datetime', editorOptions: { timeFormat: '12h' // 2:30 PM }}Combined Format Example
{ field: 'timestamp', header: 'Timestamp', editor: 'datetime', editorOptions: { dateFormat: 'MM/DD/YYYY', timeFormat: '12h', showSeconds: false }}// Output: 12/23/2024 2:30 PMThe DateTime editor displays date and time as separate inputs but stores them as a single timestamp value.
UI Components
The DateTime editor combines two UI components:
- Date Calendar: Calendar popup for date selection (from DateEditor)
- Time Picker: Hour/minute/second controls (from TimeEditor)
{ field: 'eventDateTime', header: 'Event Date & Time', editor: 'datetime', editorOptions: { dateFormat: 'MMMM DD, YYYY', timeFormat: '12h', showSeconds: false, theme: 'auto' }}Seconds Display
Control whether seconds are shown:
{ editor: 'datetime', editorOptions: { showSeconds: false // 2024-12-23 14:30 }}{ editor: 'datetime', editorOptions: { showSeconds: true // 2024-12-23 14:30:45 }}Date Constraints
Restrict the selectable date range:
{ field: 'scheduledFor', header: 'Scheduled For', editor: 'datetime', editorOptions: { dateFormat: 'YYYY-MM-DD', timeFormat: '24h', minDate: new Date().toISOString().split('T')[0] }}{ editor: 'datetime', editorOptions: { minDate: '2024-01-01', maxDate: '2024-12-31', dateFormat: 'YYYY-MM-DD' }}Validation
Add custom validation for date-time values:
{ field: 'appointmentDateTime', header: 'Appointment', editor: 'datetime', editorOptions: { dateFormat: 'MM/DD/YYYY', timeFormat: '12h', validator: (value: string) => { const date = new Date(value); const hours = date.getHours(); const day = date.getDay();
// Check weekday if (day === 0 || day === 6) { return 'Appointments only available on weekdays'; }
// Check business hours (9 AM - 5 PM) if (hours < 9 || hours >= 17) { return 'Appointments only between 9 AM and 5 PM'; }
return true; } }}{ editor: 'datetime', editorOptions: { validator: (value: string) => { const selected = new Date(value); const now = new Date(); if (selected <= now) { return 'Must select a future date and time'; } return true; } }}Popup Behavior
The calendar popup closes:
- When a date is selected
- When Escape is pressed
- When clicking outside (if configured)
- When scrolling (if
closeOnScroll: true)
{ editor: 'datetime', editorOptions: { closeOnScroll: true, // Close on scroll commitOnBlur: true // Save on click outside }}Use closeOnScroll: true to prevent the calendar from appearing misaligned when the grid is scrolled.
Theming
Customize the appearance:
{ editor: 'datetime', editorOptions: { theme: 'dark' // 'light', 'dark', or 'auto' }}Keyboard Navigation
The DateTime editor supports keyboard navigation:
- Tab: Switch between date and time inputs
- Arrow keys: Navigate calendar or adjust time
- Enter: Commit and close editor
- Escape: Cancel and close editor
Complete Examples
Event Scheduling
{ field: 'eventStart', header: 'Event Start', editor: 'datetime', editorOptions: { dateFormat: 'MMMM DD, YYYY', timeFormat: '12h', showSeconds: false, minDate: new Date().toISOString().split('T')[0], theme: 'auto', required: true, placeholder: 'Select date and time' }}Appointment Booking
{ field: 'appointmentDateTime', header: 'Appointment', editor: 'datetime', editorOptions: { dateFormat: 'MM/DD/YYYY', timeFormat: '12h', minDate: new Date().toISOString().split('T')[0], commitOnBlur: true, closeOnScroll: true, validator: (value: string) => { const dt = new Date(value); const day = dt.getDay(); const hours = dt.getHours();
if (day === 0 || day === 6) { return 'No appointments on weekends'; }
if (hours < 9 || hours >= 17) { return 'Appointments from 9 AM to 5 PM'; }
return true; } }}Log Timestamp
{ field: 'logTimestamp', header: 'Timestamp', editor: 'datetime', editorOptions: { dateFormat: 'YYYY-MM-DD', timeFormat: '24h', showSeconds: true, theme: 'dark', commitOnBlur: true }}Deadline Picker
{ field: 'deadline', header: 'Deadline', editor: 'datetime', editorOptions: { dateFormat: 'DD/MM/YYYY', timeFormat: '24h', minDate: new Date().toISOString().split('T')[0], required: true, validator: (value: string) => { const deadline = new Date(value); const now = new Date(); const hoursDiff = (deadline.getTime() - now.getTime()) / (1000 * 60 * 60);
if (hoursDiff < 24) { return 'Deadline must be at least 24 hours from now'; }
return true; } }}Value Format
The DateTime editor returns ISO 8601 formatted strings:
// Example output"2024-12-23T14:30:00.000Z"
// Parse in codeconst date = new Date(value);const formattedDate = date.toLocaleDateString();const formattedTime = date.toLocaleTimeString();Internally, values are stored as ISO 8601 strings for consistent parsing and serialization.
Integration with DateEditor and TimeEditor
The DateTime editor reuses components from DateEditor and TimeEditor:
// DateEditor provides:// - Calendar popup// - Date parsing and formatting// - Date validation
// TimeEditor provides:// - Time picker UI// - Time parsing and formatting// - Time validation
// DateTimeEditor combines bothBest Practices
- Match user locale: Use appropriate date/time formats for your users
- Validate business rules: Check working hours, weekdays, lead times
- Set appropriate constraints: Use minDate/maxDate for valid ranges
- Handle timezones: Be aware of timezone implications for stored values
- Provide clear feedback: Use validation messages to guide users
{ field: 'meetingDateTime', header: 'Meeting Time', editor: 'datetime', editorOptions: { dateFormat: 'MM/DD/YYYY', timeFormat: '12h', showSeconds: false, minDate: new Date().toISOString().split('T')[0], theme: 'auto', closeOnScroll: true, commitOnBlur: true, required: true, placeholder: 'Select meeting time', validator: (value: string) => { if (!value) return 'Meeting time is required'; const dt = new Date(value); const day = dt.getDay(); const hours = dt.getHours();
if (day === 0 || day === 6) { return 'Meetings on weekdays only'; }
if (hours < 9 || hours >= 17) { return 'Meetings between 9 AM and 5 PM'; }
return true; } }}