I am looking to remove the day of the week when sorting a column using Mottie Tablesorter v2.31.
The value of the cells are as follows: Friday, 9/15/2023 at 7:00AM.
Here is what I have so far based on the documents in Mottie but nothing is happening.
I have also attempted to add in things such as alerts to see if it is even hit, and I get nothing.
$(function () {
$("table").tablesorter({
theme: "bootstrap",
widthFixed: true,
// widget code contained in the jquery.tablesorter.widgets.js file
// use the zebra stripe widget if you plan on hiding any rows (filter widget)
// the uitheme widget is NOT REQUIRED!
widgets: ["filter", "columns", "zebra", "filter_functions"],
widgetOptions: {
// using the default zebra striping class name, so it actually isn't included in the theme variable above
// this is ONLY needed for bootstrap theming if you are using the filter widget, because rows are hidden
zebra: ["even", "odd"],
// class names added to columns when sorted
columns: ["primary", "secondary", "tertiary"],
// reset filters button
filter_reset: ".reset",
// extra css class name (string or array) added to the filter element (input or select)
filter_cssFilter: [
'form-control',
'form-control',
'form-control', // select needs custom class names :(
'form-control',
'form-control',
'form-control'
],
filter_functions: {
// function(e, n, f, i, $r, c, data) {} <- current parameters
5: function (e, n, f, i, $r, c, data) {
// Get the date value from the cell
var date = $(n).text().trim();
// Remove the day of the week from the date string
var formattedDate = date.substr(date.indexOf(",") + 2);
// Return the formatted date for filtering
return formattedDate;
} // planned change (version undetermined)
}
}
})
});
The way the tablesorter filters is found here
You need to perform a test that will return true if you want to show the row or false if you want to hide it.
I have changed some of the parameter names so they make more sense
We take the normalised (lowercased) value and remove the dayname, that way you can search for
aand get AM instead of...day- that, and the ignoring of any entering of dayname is what the script does. That does mean that if you DO enter a dayname, nothing is shown so I still do not quite get what you want. If you want to ignore that users enter daynames, then we also need to remove that from the normalised string while they enter it. I would be a bit confused by that as a user.In any case the script below is a great start.