Moment.js filtering only before day 12
Moment.js filtering only before day 12
cihank
Posts: 1Questions: 0Answers: 0
I have a datatable and using moment for filtering date. My problem is if i enter days before day 12 is working fine but after day 12 not filtering my data. For example the date between 01/01/2021 and 12/01/2021 is working fine but if i enter 01/01/2021 and 13/01/2021 not getting any data.
// Extend dataTables search
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var min = $('#min-date').val();
var max = $('#max-date').val();
var createdAt = data[0] || 0; // Our date column in the table
moment().format('DD/MM/YYYY');
if (
(min == "" || max == "")
||
(moment(createdAt, 'DD/MM/YYYY').isSameOrAfter(min, 'DD/MM/YYYY') && moment(createdAt, 'DD/MM/YYYY').isSameOrBefore(max, 'DD/MM/YYYY'))
) {
return true;
}
return false;
}
);
function dtConvFromJSON(data) {
if (data == null) return '1/1/1950';
var r = /\/Date\(([0-9]+)\)\//gi
var matches = data.match(r);
if (matches == null) return '1/1/1950';
var result = matches.toString().substring(6, 19);
var epochMilliseconds = result.replace(
/^\/Date\(([0-9]+)([+-][0-9]{4})?\)\/$/,
'$1');
var b = new Date(parseInt(epochMilliseconds));
var c = new Date(b.toString());
var curr_date = c.getDate();
var curr_month = c.getMonth() + 1;
var curr_year = c.getFullYear();
var curr_h = c.getHours();
var curr_m = c.getMinutes();
var curr_s = c.getSeconds();
var curr_offset = c.getTimezoneOffset() / 60
var d = curr_date.toString() + '/' + curr_month.toString() + '/' + curr_year.toString();
return d;
}
Iam using dtConvFromJson function here ;
"columns": [
{ "data": "Date", render: function (data, type, full) { return dtConvFromJSON(data); }, "autoWidth": true },
This discussion has been closed.
Replies
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin