javascript - Use DatePicker to filter DataTable -
i have datatable named 'search_table' in page. have additional header row in table has different filter options (dropdown, text, date_pickers). date columns, have 2 datepickers, 1 min , 1 max. can filter data datatable based on datepickers, there 1 problem:
when select date, rows in table disappear, have click on 1 of headers (like sort data) data appear. once so, correct data shows (the dates between min , max).
what functionality use force datapicker re-draw table? in ready function, have 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 , max_update inputs have datepicker class. search_table table datatable.
i had 2 issues when fixed solved problem.
in ready function, had
var table = $('#search_table').datatable();
this should have been
var table = $('#search_table').datatable();
then, in code datepicker class had
$(".datepicker").datepicker( { maxdate:0, changemonth: true, changeyear: true, dateformat: 'yy-mm-dd', onclose: function(selecteddate) { table.draw();}});
and needs changed
$(".datepicker").datepicker( { maxdate:0, changemonth: true, changeyear: true, dateformat: 'yy-mm-dd', onclose: function(selecteddate) { table.fndraw();}});
Comments
Post a Comment