Use Buttons to Search a Date Within a Range

The idea behind this method is to create a user experience where a user can click a date button on a page and then will be able to see details for…

  • Not yet re-checked
  • Classic builder

Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

Screenshot for “Use Buttons to Search a Date Within a Range”

The idea behind this method is to create a user experience where a user can click a date button on a page and then will be able to see details for records on that date.

Step 1

Add the custom JavaScript pipe and set the parameters as seen in the image below.

Screenshot for “Use Buttons to Search a Date Within a Range”

Step 2

In the request tab of the pipe, add the following request.

Text
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
}
var retVal = "", current = new Date('{start}'), end = new Date('{end}');
while (current <= end) {
  retVal+=current.toLocaleDateString('en-CA', {day: '2-digit',month: '2-digit',year: 'numeric',})+" ";
  current = current.addDays(1);
 }
retVal;
Screenshot for “Use Buttons to Search a Date Within a Range”

Step 3

In your data table, set up the pipe to trigger a table rule when the record is created or edited.

Screenshot for “Use Buttons to Search a Date Within a Range”

Step 4

On your page, add a search component and link it to the components you wish to search for. In the fields tab of the search component, select list dates and set the operators as seen in the image below.

Screenshot for “Use Buttons to Search a Date Within a Range”

Step 5

In the system component selections, add an HTML component to your page. In the settings, add the following to the source code <>.

Text
<table style="height: 51px;" width="722">
    <tbody>
        <tr>
            <td style="width: 174px;"><button class="btn btn-primary btn-sm date-link" data-value="0">Today</button></td>
            <td style="width: 174px;"><button class="btn btn-primary btn-sm date-link" data-value="1">Tomorrow</button></td>
            <td style="width: 174px;"><button class="btn btn-primary btn-sm date-link" data-value="2">2</button></td>
            <td style="width: 174px;"><button class="btn btn-primary btn-sm date-link" data-value="3">3</button></td>
        </tr>
    </tbody>
</table>
Screenshot for “Use Buttons to Search a Date Within a Range”

Step 5

In the JavaScript tab of the page, add the following code.

Text
TB.render('component_24', function(data) {
    TB.hideComponent('component_12');
    var links = document.getElementsByClassName("date-link"),
        days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    for (var x = 2; x < links.length; x++) {
        var date = new Date();
        date.setDate(date.getDate() + x);
        console.log(date);
        links[x].innerHTML = days[date.getDay()] + " " + date.getDate();
    }
    $(".date-link").click(function() {
        var date2 = new Date();
        date2.setDate(date2.getDate() + parseFloat(this.dataset.value));
        window.location = "#!/default?date=" + date2.toLocaleDateString('en-CA', {
            day: '2-digit',
            month: '2-digit',
            year: 'numeric',
        });
        location.reload();
    });
});
Screenshot for “Use Buttons to Search a Date Within a Range”
Screenshot for “Use Buttons to Search a Date Within a Range”

Original Community Post:

Use Buttons to Search a Date Within a Range - Community Discussions / How to Do I - Tadabase Community

Was this page helpful?

Something wrong or missing on this page? Tell us.