Datatables date range picker 적용, 날짜 검색 기능(date range filter)
Devel/그 외 ...2022. 1. 22. 00:00
반응형
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css"/>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css"/>
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.11/jquery.mask.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script>
$(document).ready(function() {
// Bootstrap datepicker
$('.input-daterange input').each(function() {
$(this).datepicker('clearDates');
});
// Extend dataTables search
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
var min = $('#min').val();
var max = $('#max').val();
var createdAt = data[1] || 1; // Our date column in the table
if (
(min == "" || max == "") ||
(moment(createdAt).isSameOrAfter(min) && moment(createdAt).isSameOrBefore(max))
) {
return true;
}
return false;
}
);
// Re-draw the table when the a date range filter changes
$('.date-range-filter').change(function() {
var table = $('#data-table').DataTable();
table.draw();
});
$('.date-range-filter').datepicker();
});
</script>
'Devel > 그 외 ...' 카테고리의 다른 글
PHP 날짜 차이 구하는 법 (0) | 2022.03.16 |
---|---|
Mac(맥) Homebrew 설치 및 확인 방법 (0) | 2022.03.08 |
datatables 특정 컬럼 숨기기, hide 처리 (0) | 2022.01.21 |
Datatables date range filter 설정(데이터 테이블 날짜 범위 설정) (0) | 2022.01.20 |
Git commit , push 되돌리기, 취소/삭제하기 (0) | 2022.01.14 |
댓글()