Last active
June 2, 2026 10:14
-
-
Save annuman97/072832afa995036ac25433156a73f05b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Ninja Tables - Current Month Date Range Filter | |
| * | |
| * Automatically applies the current month date range | |
| * to a Ninja Tables custom date range filter on page load. | |
| * | |
| * Date Format: DD/MM/YYYY | |
| * | |
| * Example: | |
| * From Date: 01/06/2026 | |
| * To Date: 30/06/2026 | |
| */ | |
| (function ($) { | |
| 'use strict'; | |
| function formatDateDDMMYYYY(date) { | |
| var day = String(date.getDate()).padStart(2, '0'); | |
| var month = String(date.getMonth() + 1).padStart(2, '0'); | |
| var year = date.getFullYear(); | |
| return day + '/' + month + '/' + year; | |
| } | |
| function applyCurrentMonthDateRangeFilter() { | |
| var $filterWrapper = $('#nt_cf_3_table_28843').closest('.ninja_custom_date_filter'); | |
| //change the date range input box ID: https://prnt.sc/SvOcjXFBeO76 | |
| if (!$filterWrapper.length) { | |
| return; | |
| } | |
| var today = new Date(); | |
| var firstDay = new Date(today.getFullYear(), today.getMonth(), 1); | |
| var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0); | |
| var fromDate = formatDateDDMMYYYY(firstDay); | |
| var toDate = formatDateDDMMYYYY(lastDay); | |
| var $fromInput = $filterWrapper.find('.ninja_filter_date_from'); | |
| var $toInput = $filterWrapper.find('.ninja_filter_date_to'); | |
| $fromInput.attr('data-date_format', 'DD/MM/YYYY'); | |
| $toInput.attr('data-date_format', 'DD/MM/YYYY'); | |
| $fromInput.val(fromDate).trigger('input').trigger('change'); | |
| $toInput.val(toDate).trigger('input').trigger('change'); | |
| setTimeout(function () { | |
| $fromInput.trigger('change'); | |
| $toInput.trigger('change'); | |
| }, 300); | |
| } | |
| $(document).ready(function () { | |
| setTimeout(function () { | |
| applyCurrentMonthDateRangeFilter(); | |
| }, 800); | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment