-
Notifications
You must be signed in to change notification settings - Fork 2
datetime
Johannes Wilm edited this page Sep 17, 2018
·
20 revisions
Simple DataTables utilizes the MomentJS library for parsing datatime strings for easier column sorting.
Define a data-type
attribute on the headings and set the value to date
. If the datatime string is in a format that can not be sorted easily by standard methods, you must define the data-format
attribute and set it's value to the format that is expected.
<table>
<thead>
<th data-type="date" data-format="DD/MM/YYYY"></th>
<th data-type="date" data-format="MM/DD/YY"></th>
...
</thead>
</table>
The date
and format
strings can also be defined in the options using the columns
property:
// Allow sorting of the first column with "DD/MM/YYYY" format
let datatable = new DataTable("#myTable", {
columns: [
{
select: 0,
type: "date",
format: "DD/MM/YYYY"
}
]
});
// Apply formatting to the third and fourth columns as well
let datatable = new DataTable("#myTable", {
columns: [
{
select: 0,
type: "date",
format: "DD/MM/YYYY"
},
{
select: [2,3],
type: "date",
format: "MM/DD/YY"
}
]
});
As well as custom format strings, there are some pre-defined formats that you can utilise:
ISO_8601
RFC_2822
MYSQL
// Allow sorting of the third column by MySQL datetime strings
let datatable = new DataTable("#myTable", {
columns: [
{
select: 2,
type: "date",
format: "MYSQL"
}
]
});
- datatable.init
- datatable.refresh
- datatable.update
- datatable.page
- datatable.sort
- datatable.perpage
- datatable.search
- ajax
- columns
- data
- firstLast
- firstText
- fixedColumns
- fixedHeight
- footer
- header
- labels
- layout
- lastText
- nextPrev
- nextText
- paging
- perPage
- perPageSelect
- prevText
- scrollY
- searchable
- sortable
- truncatePager
- table
- head DEPRECATED
- body DEPRECATED
- foot DEPRECATED
- wrapper
- container
- pagers
- headings
- options DEPRECATED
- initialized
- isIE DEPRECATED
- data
- activeRows DEPRECATED
- dataIndex
- pages
- hasRows
- hasHeadings
- currentPage
- totalPages
- onFirstPage
- onLastPage
- searching
- searchData