Created
December 17, 2013 16:37
-
-
Save mohitmayank/8007958 to your computer and use it in GitHub Desktop.
Bootstrap based Date picker formatter for tablesorter (https://github.com/Mottie/tablesorter) using https://github.com/tarruda/bootstrap-datetimepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bootstrapDatepicker = function($cell) { | |
var $minDateField = $('<div class="input-prepend minDateFilterField"><span class="add-on"><i data-time-icon="icon-chevron-right" data-date-icon="icon-chevron-right"></i></span><input class="forceHide" type="text"></div>').appendTo($cell); | |
$minDateField.datetimepicker({ | |
pickDate: true, | |
pickTime: false, | |
format : "dd-MM-yyyy" | |
}); | |
var minDatePicker = $minDateField.find('input'); | |
var $input = $('<input type="text" class="dateFilterField"/>').appendTo($cell); | |
var $maxDateField = $('<div class="input-append maxDateFilterField"><input class="forceHide" type="text"><span class="add-on"><i data-time-icon="icon-chevron-left" data-date-icon="icon-chevron-left"></i></span></div>').appendTo($cell); | |
$maxDateField.datetimepicker({ | |
pickDate: true, | |
pickTime: false, | |
format : "dd-MM-yyyy" | |
}); | |
var maxDatePicker = $maxDateField.find('input'); | |
$minDateField.on('changeDate', function(){ | |
if(maxDatePicker.val() !== '') { | |
$input.val(minDatePicker.val() + ' - ' + maxDatePicker.val()); | |
} else { | |
$input.val('>= ' + minDatePicker.val()); | |
} | |
$input.trigger('search'); | |
}); | |
$maxDateField.on('changeDate', function(){ | |
if(minDatePicker.val() !== '') { | |
$input.val(minDatePicker.val() + ' - ' + maxDatePicker.val()); | |
} else { | |
$input.val('<= ' + maxDatePicker.val()); | |
} | |
$input.trigger('search'); | |
}); | |
$input.change(function(){ | |
if($input.val() === '') { | |
minDatePicker.val(''); | |
maxDatePicker.val(''); | |
} | |
return false; | |
}); | |
return $input; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This demo shows how to use the filter with dangrossman/bootstrap-daterangepicker plugin.