React Data Table Component and Moment - reactjs

I am using React Data Table Component for displaying table data - which works great!
I have a row field for lastLogin time, which is stored in MongoDB as a model like so:
lastLogin: [{
type: Date,
required: false,
}],
My data table component looks like so:
<DataTable
noHeader
pagination
paginationPerPage={15}
paginationRowsPerPageOptions={paginationRowsPerPageOptions}
responsive
columns={columns}
sortIcon={<ChevronDown />}
className="react-dataTable"
data={store.data}
/>
Using columns when I try and render the date without moment, it works fine:
{
name: 'Last Login',
selector: (row) => row.lastLogin,
},
will result in:
row 1: 2021-11-17T01:16:55.093Z
row 2: (empty)
However, when formatting with moment, it seems to be obtaining the previous records results.
{
name: 'Last Login',
selector: (row) => row.lastLogin,
format: (row) => moment(row.lastLogin).format('lll'),
},
will result in:
row 1: Jan 1, 2021 12:00 AM
row 2: Nov 17, 2021 1:15 PM

This code is work correct, and the result its expected base on how the moment work.
moment work with current time as a default time to do a process, so that, if you pass a date value, then you will work and format this value, else will work and format current date.
for example:
var now = moment(undefined).format('lll');
console.log(now)
this will be equl for:
var now2 = moment().format('lll');
console.log(now2)
Demo Link

Ok... this one has been resolved... silly syntax error.
The login date on the model was setup as an array:
lastLogin: [{
type: Date,
required: false,
}],
Should be:
lastLogin: {
type: Date,
required: false,
},

Related

How do you setup Material UI DataGrid Initial State Filter Model for Date?

I want to render a Matial UI datagrid with an initial filter model so only upcoming dates are shown. (until the user clears the default set filter)
I have no problems creating a filter for the date after the datagrid is loaded without any initialState set.
manually setting filters after rendered datagrid
However! When I attempted the initial filter model involving the date column
initialState = {{
filter: {
filterModel:{
items: [{
columnField: 'class_end_date',
operatorValue: 'onOrAfter',
value: new Date()
}],
}
}
}}
I continually get Uncaught TypeError: filterItem.value.match is not a function
top of the stacktrace
buildApplyFilterFn gridDateOperators.js:10
getApplyFilterFn gridDateOperators.js:62
Errors resulting from default filter model
I am assuming there's some kind of type conversion I need for the value property in the items filter object. Still researching, but I can't find anything helpful in MUI docs hence far.
If anyone has tackled this one I'd be grateful for a step in the right direction! Thank you.
I also ensured that my type and valueGetter were defined appropriately in my columns array. Remember I want an initial state filter model for class_end_date
{
field: 'class_start_date',
headerName: 'Start Date',
width: 140,
type: 'date',
valueGetter: (params) => {
return new Date(params.value)
}
},
{
field: 'class_end_date',
headerName: 'End Date',
width: 140,
type: 'date',
valueGetter: (params) => {
return new Date(params.value)
}
},
I've also tried using dateTime for the column type, formatting the dates from the valueGetters and the filtermodel value to mm/dd/yyyy format,
and I tried ensuring the value property was a string
filterModel:{
items: [{
columnField: 'class_end_date',
operatorValue: 'onOrAfter',
value: `${new Date()}`
}],
}

Extjs - How to access/modify the data before the Ext.data.Batch starts

-- Extjs - 6.6.0, Extjs Grid with Cell Editing plugin, record save operation to the server
There is a grid in my application interface with a proper store and model attached to the store. The grid has a date column with a date editor with the render format as 'd-M-Y' and the date value to submit to the server is 'Y-m-d'. During the save operation through a batch start with the session, I am unable to access the data to modify the date format to 'Y-m-d' and is being submitted as 'd-M-Y' which causing an issue.
Can anyone please provide the information on accessing/modifying the data before the Ext.Data.Batch starts.
Note:
I cannot replace the batch with Ajax call.
I already tried dateWriteFormat for the Model class as well.
The date display & submit formats must be 'd-M-Y' & 'Y-m-d'.
I cannot post the code as it is too large.
Any sort of help would be much appreciated.
There are a couple of ways.
FIELD
You might want to edit the Model of the store via serialize.
Ext.define('MyApp.model.Users', {
extend: 'Ciss.data.Model',
fields: [{
name: 'BirthDate',
type: 'date',
dateFormat: 'd m Y', // how the date format comes from the server
serialize: function (val) {
return Ext.Date.format(val, 'Y-m-d');
}
}];
});
WRITER
You can use the writer using the dateFormat
writer: {
type: 'json',
dateFormat: 'Y-m-d',
writeAllFields: true
}
while your field should be of the type date, all the time
If you still need more control you can use the transform method.
Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url : 'users.json',
writer: {
type: 'json',
transform: {
fn: function(data, request) {
// do some manipulation of the unserialized data object
return data;
},
scope: this
}
}
},
});
EVENT
You can use the store beforesync event
LAST HOPE
If all this does not work for you you can grab every request before it's send.

Selecting date gives an object, not the dates

When I select dates and apply the filter, the startDate and endDate both are objects and i can't seem to be able to get the selected days.
I have already tried to select the attributes inside of the object, but it doesn't give me a good date.
I have the following code:
CONTROLLER
$scope.datePicker = {
date: {startDate: null, endDate: null},
options: {
maxSpan: {
days: 31
},
maxDate: moment(),
locale: {
separator: ' - ',
format: "D/MM/YYYY"
},
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro',
'Outubro', 'Novembro', 'Dezembro'
]
}
};
HTML
<input class="filter-select date-picker" type="text"
date-range-picker
options="datePicker.options"
max="datePicker.options.maxDate"
ranges="datePicker.opstions.maxSpan.days"
ng-model="datePicker.date" />
I also have a watcher that logged the following image:
Does anyone knows how to get the the startDate and endDate values as a simple string or a Date format?
You can use moment to get the date with the format you expect.
For Example:
let startDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
let endDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
To know about various date formats you can check this on moment date formats

ExtJS 4.2 Show a 1 - 12 Month Dynamic calendar

In my ExtJS 4.2 Application I have the requirement to show from 1 to 12 months calendar depending on the Holiday calendar from a selected employee.
I need to show something like this:
So from the above approach I think this can be done by using DatePicker components (as many as needed)
I also found this sample of how to show a complete year info:
From the above sample I think the approach would be creating a dynamic grid with custom columns and rows.
Anyone has done something similar so can give me an idea of the best way to achieve this?
Appreciate in advance.
I used Extensible.calendar
Ext.define('App.view.calendar.calendar_v', {
extend: 'Extensible.calendar.CalendarPanel',
requires: ['Ext.panel.*',
'Extensible.calendar.data.MemoryEventStore',
'Extensible.calendar.CalendarPanel',
'Ext.toolbar.*',
'Ext.button.*',
'Ext.container.ButtonGroup',
'Ext.selection.CellModel',
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.form.*',
'Ext.tip.QuickTipManager',
'Ext.form.field.ComboBox',
'Ext.layout.container.Table'],
controllers: ['Main'],
eventStore: eventStore,
xtype: 'calendar',
title: 'Custom Views',
width: 800,
height: 700,
activeItem: 3,
// These show by default, turn them off
showDayView: true,
showMonthView: true,
// Defaults to 3 days. You could also set the dayCount config
// inside multiDayViewCfg to change that.
showMultiDayView: true,
// Used with the custom week view configured below
weekText: 'Week',
weekViewCfg: {
// These settings create a fixed weekday view.
// This view will only show Mon-Fri.
dayCount: 5,
// Always start the view on Monday
startDay: 1,
startDayIsStatic: true,
// NOTE: the configs below apply to any DayView or WeekView. If you wanted all day
// and week views to share these same settings, you could simply pass these configs
// in the general viewCfg. Any views that do not use them will ignore them. They are
// only on this view in this sample to demonstrate how they can be easily customized per view.
// Hide the half-hour marker line
showHourSeparator: false,
// Start the view at 6:00
viewStartHour: 6,
// End the view at 8:00pm / 20:00
viewEndHour: 20,
// Default the scroll position on load to 8:00 if the body is overflowed
scrollStartHour: 8,
// Customize the hour (and event) heights. See the docs for details on setting this.
// This example will be double-height (the default is 42)
hourHeight: 84,
// Allow drag-drop, drag-create and resize of events in 10-minute increments
ddIncrement: 10,
// Since the hour blocks are double-height, we can shorten the minimum event display
// height to match the ddIncrement
minEventDisplayMinutes: 10
}
});
And then I load in events from a store
var x = 1;
var u = Ext.data.StoreManager.lookup('calendar.calendar_s');
u.load({
callback: function () {
Ext.each(Ext.data.StoreManager.lookup('calendar.calendar_s').data.items, function (value) {
eventStore.add({
CalendarId: (x + 1),
EndDate: value.data.date,
IsAllDay: true,
Location: "",
Notes: notes,
RecurRule: "",
Reminder: "",
StartDate: value.data.date,
Title: "",
Url: "sumpnsumpn"
})
});
}
});

How can I get a GridPanel to show the correct time in ExtJS 4?

I have a GridPanel with ExtJS 4. One of the columns returns a timestamp in the following format:
1900-01-01 14:00:00.0
This is my column from my JsonStore
{
name: 'clockOut',
mapping: 'clockOut',
dateFormat: 'H:i A',
type: 'date'
}
I just want to show the time section but all I get back is a blank column.
When I remove the type: 'data' I get the data but in the above format.
Any suggestions?
Thanks
You could add a renderer to the column that formats it the way you want:
{
name: 'clockOut',
mapping: 'clockOut',
renderer: dateRenderer
}
And then a function for dateRenderer:
function dateRenderer(value, id, r) {
var d = new Date(r.data['clockOut']);
return d.format('H:i A');
}
You could even use ExtJS built in renderer instead of defining your own function:
renderer: Ext.util.Format.dateRenderer('H:i A')

Resources