How is the searchBuilder able to handel the time format hh:mm:ss?
How is the searchBuilder able to handel the time format hh:mm:ss?
Link to test case:
https://live.datatables.net/xicidaxu/1/edit
Description of problem:
I have multiple columns with data in the time format hh:mm:ss for exampel 08:55:00.
I want to use the searchbuilder to be able to make a filter like:
1. show me all data in column 2 between 08:55:00 and 09:40:22.
2. show me all data in column 2 greather than 08:55:00
3. show me all data in column 2 less than 08:55:00
Thank you for help!
Additional information:
I configured my first column date right. Searchbuilder noticed through my javascript code the German date format dd.mm.YYYY
Column 2 to 5 are all columns with time data.
In column 2 i tried to solve my problem with this code snippet but it doesn't work:
searchBuilderType: 'date',
data: 1,
render: function(data, type, row, meta) {
if (type === 'filter') {
return luxon.DateTime.fromFormat(data, 'HH:mm:ss').toFormat('HH:mm:ss');
}
return data;
},
searchBuilder: function(settings, searchData, dataIndex) {
var minTime = settings.globals.minTime;
var maxTime = settings.globals.maxTime;
var timeData = searchData[dataIndex];
var timeLuxon = luxon.DateTime.fromFormat(timeData, 'HH:mm:ss');
var isValid = true;
if (minTime) {
var minTimeLuxon = luxon.DateTime.fromFormat(minTime, 'HH:mm:ss');
isValid = isValid && timeLuxon >= minTimeLuxon;
}
if (maxTime) {
var maxTimeLuxon = luxon.DateTime.fromFormat(maxTime, 'HH:mm:ss');
isValid = isValid && timeLuxon <= maxTimeLuxon;
}
return isValid;
}
},
For column 3 i tried another approach. I convertet the hh:mm:ss to seconds with a clalcluation. This works but it isn't user friendly to calculate everthing in seconds by yourself before setting the filter.
Answers
columns: [
{
searchBuilderType: 'date',
render: function(data, type, row, meta) {
if (type === 'display') {
return luxon.DateTime.fromFormat(data, 'dd.MM.yyyy').toFormat('dd.MM.yyyy');
} else if (type === 'filter') {
return luxon.DateTime.fromFormat(data, 'dd.MM.yyyy').toFormat('yyyy-MM-dd');
}
return data;
}
},
null,
null,
null,
null,
null,
null
],
My solution is the upper code. But I am not completly happy with it cuz now the column 1 is permanently formated in yyyy-MM-dd so other filters wouldn't work anymore.