Js filter function problem.
Js filter function problem.
Hi,
I have the following javascript code:
$(document).ready(function() {
// Sort dates code
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"extract-date-pre": function(value) {
var date = $(value, 'span')[0].innerHTML;
date = date.split('/');
return Date.parse(date[1] + '/' + date[0] + '/' + date[2])
},
"extract-date-asc": function(a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"extract-date-desc": function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
// Datable
var table = $('#tabla5').DataTable({
"pagingType": "full_numbers",
language: {
url: '\\Spanish.json'
},
columnDefs: [{
type: 'extract-date',
targets: [1] // [1] es la columna fecha
}]
});
// date filter listener
$('#min').keyup( function() { table.draw(); } );
$('#max').keyup( function() { table.draw(); } );
});
The code (// Sort dates code) I use to sort dates with the format dd / mm / yyyy. It works ok.
On the other hand (// date filter listener) I use it to filter the dates between two values captured with inputs.
My problem is that the function to sort dates and the function to filter dates do not work together:
- If I delete // sort dates code, the filter between two dates works.
- If I delete // date filter listener, the date arrangement dd / mm / yyyy works.
What can I do to make all my js work at once?
THANKS!
Replies
I forgot to say that this part of the code:
works with range_dates.js:
Hi @pirate666 ,
At a glance it looks like it should be OK. Would you be able to create a test case so we can see it running? 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
live.datatables.net/sozoxaxo/1/edit
I have the same code as in this test page, in whick everything works perfectly >.<
But, in my localhost web, the date filter not working with
I have no idea how to fix it
Hi @pirate666 ,
That's odd it works on that test page, but not locally. Are you using the same versions of DataTables/jQuery/etc, and are they all defined in the same order? I'm really not sure what to suggest other than that!
Could you link to your page? Would that be possible?
Cheers,
Colin
The truth is that I do not know what the problem was. I copied the same file in another location and it worked: S. Thank you very much for your help @colin !