Friday, 29 April 2016
Jquery table sorter date in any format dd/mm/yyyy or dd.mm.yyyy using tablesorter plugin
Here I will explain about how to sort a date format in html table using simple jquery functionality. Here I am using jquery parser to sort a date format. Using tablesorter plugin you can also put an default sorting column.
In my code dateformat as dd/mm/yyyy.
Write this function outside the document.ready() function.
$.tablesorter.addParser({
// set a unique id
id: 'myDateFormat',
is: function (s) {
return false;
},
format: function (s) {
debugger;
var date = s.split('/');//Change the special character whatever you will be used in your date format like "/,or."
return new Date(date[2], date[1], date[0]).getTime();
},
type: 'numeric'
});
Write below code in document.ready() function
$('#tabCustomersData').tablesorter({
sortList: [[3, 0]], //Sort will be on 3rd column
headers:
{
3: { sorter: "myDateFormat" }
}
In my code dateformat as dd/mm/yyyy.
Write this function outside the document.ready() function.
$.tablesorter.addParser({
// set a unique id
id: 'myDateFormat',
is: function (s) {
return false;
},
format: function (s) {
debugger;
var date = s.split('/');//Change the special character whatever you will be used in your date format like "/,or."
return new Date(date[2], date[1], date[0]).getTime();
},
type: 'numeric'
});
Write below code in document.ready() function
$('#tabCustomersData').tablesorter({
sortList: [[3, 0]], //Sort will be on 3rd column
headers:
{
3: { sorter: "myDateFormat" }
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment