Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  20] [ 3]  / answers: 1 / hits: 23611  / 9 Years ago, mon, june 29, 2015, 12:00:00

I have a DataTable named 'search_table' in my page. I have a additional header row in the table that has different filter options (dropdown, text, date_pickers). For the date columns, I have two datepickers, one for min and one for max. I can filter the data for the datatable based on the datepickers, but there is one problem:



When I select a date, all the rows in my table disappear, I have to click on one of the headers (like to sort the data) to get the data to appear. Once I do so, the correct data shows (the dates are between min and max).



What functionality do I use to force the datapicker to re-draw the table? In my ready function, I have the following code:



      $(document).ready(function() {
var table = $('#search_table').DataTable();
$(.datepicker).datepicker( {
maxDate:0,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onClose: function(selectedDate) {
table.draw();}});
$('#min_create, #max_create, #min_update, #max_update').keyup(function() { table.draw(); });
$('#min_create, #max_create, #min_update, #max_update').click( function() { table.draw(); });
$('#min_create').datepicker().bind('onClose', function(){ table.draw(); });
});


min_create, max_create, min_update and max_update are all inputs that have the datepicker class. search_table is my table that is a DataTable.


More From » jquery

 Answers
28

I had two issues that when fixed solved my problem.



In my ready function, I had



var table = $('#search_table').DataTable();


this should have been



var table = $('#search_table').dataTable();


Then, in the code for the datepicker class I had



  $(.datepicker).datepicker( {
maxDate:0,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onClose: function(selectedDate) {
table.draw();}});


and it needs to be changed to



  $(.datepicker).datepicker( {
maxDate:0,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onClose: function(selectedDate) {
table.fnDraw();}});

[#65993] Saturday, June 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;