DateFormate
-
- Posts: 7
- Joined: 14 Dec 2021, 17:54
You can use this code, this will change the format of a Date object
You will have to call the functions from the Column component at the body property like this:
Code: Select all
dateTemplate(rowData, field) {
return rowData[field.field].toLocaleDateString(navigator.language, {
day: '2-digit',
month: '2-digit',
year: 'numeric',
})
}
dateTimeTemplate(rowData, field) {
return rowData[field.field].toLocaleDateString(navigator.language, {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
}
Code: Select all
<Column
key={item.field}
field={item.field}
header={item.header}
body={item.datatype == "date" ? this.dateTemplate : this.dateTimeTemplate}
sortable
filter
filterType="date"
filterPlaceholder={item.filterPlaceholder}
filterField={item.field}
sortField={item.field}
style={{width: item.header.length + 1 + "rem"}}
dataType="date"
filterElement={this.dateFilterTemplate}
/>
-
- Information
-
Who is online
Users browsing this forum: No registered users and 18 guests