Filter by Date Range

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Filter by Date Range

Post by primitive_man » 2015-04-02 17:15

I've recently noted that filtering by a date range does not work correctly.

Examples:
1. UK dates (dd/mm/yyyy) are not accepted. Only the UNIX format yyyy-mm-dd.
2. Conditional 'AND' isn't accepted but 'OR' is - but the range is incorrect.

Question:
Since I only wish to EVER select a range between 2 dates - therefore only two filters are required - Is there a way of getting rid of the rest of the filters, including the 'Order By' section?

Question 2:
Since these will only be dates, can I get the Calendar to Popup ?

Any help appreciated. Thanks in advance.

User avatar
a.gneady
Site Admin
Posts: 1045
Joined: 2012-09-27 14:46
Contact:

Re: Filter by Date Range

Post by a.gneady » 2015-04-04 22:17

1. A filter like the one below would work fine (the below uses US date format, first 5 days of December 2014) ... If you set the date format for your project to UK format, using UK format in the filters page should work fine. But if the format in your project is unix format, you won't be able to search using the UK format in the filters page.
filtering-by-date-range.png
filtering-by-date-range.png (16.51 KiB) Viewed 6125 times
2. Hmm ... when using AND, the conditions should go like this:
date-field greater than or equal date1
AND date-field less than or equal date2

date2 must be greater than date 1for the above to work correctly.

You can create a customized filter page and use the tablename_init hook to assign that page as the filters page for the concerned table. For more details, please see: http://bigprof.com/appgini/help/advance ... ename_init and http://bigprof.com/appgini/help/advance ... s/DataList
:idea: Learn all the tips and tricks of customizing AppGini apps through our online course.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Re: Filter by Date Range

Post by primitive_man » 2015-04-14 19:26

Thank you for your reply, in order:

1. The date format in my project IS set to GB
2. Thank you for the correction concerning order of conditions.

Problem: It still only accepts Unix date formats. Is this possibly because the field I'm filtering on, i.e., 'Created_On' is a TimeStamp Field and NOT a date field?

User avatar
a.gneady
Site Admin
Posts: 1045
Joined: 2012-09-27 14:46
Contact:

Re: Filter by Date Range

Post by a.gneady » 2015-04-15 08:26

'Created_On' is a TimeStamp Field and NOT a date field?
Aha ... yes, that explains it indeed .. using localized date formats works only with 'date' fields .. For timestamp fields, only unix format (yyyy-mm-dd) works.
:idea: Learn all the tips and tricks of customizing AppGini apps through our online course.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Re: Filter by Date Range

Post by primitive_man » 2015-04-17 15:12

Ok.
I've managed to create a nice little date range filter that works on TimeStamp formats with a couple of pop up calendars (jQuery-UI):
Cap.jpg
Cap.jpg (4.37 KiB) Viewed 6070 times
from the information supplied here: http://bigprof.com/appgini/tips-and-tut ... arch-forms

and it does filter on the dates - but be it also shows ALL records belonging to ALL members, the default filter is not applied, ie. member ID.

Can anyone suggest a way of applying the default filter?

primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Re: Filter by Date Range

Post by primitive_man » 2015-04-17 15:37

Sorry... Cancel the above request, got it and thank you for your help yet again, a.gneady

User avatar
a.gneady
Site Admin
Posts: 1045
Joined: 2012-09-27 14:46
Contact:

Re: Filter by Date Range

Post by a.gneady » 2015-04-21 00:48

You're always welcome :D
:idea: Learn all the tips and tricks of customizing AppGini apps through our online course.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

petrescucld
Posts: 8
Joined: 2016-07-14 17:36

Re: Filter by Date Range

Post by petrescucld » 2016-07-15 12:07

How can i modify the filter page so that it includes a date range?

thank you!

Aya Adel
Posts: 7
Joined: 2016-08-08 07:29

Re: Filter by Date Range

Post by Aya Adel » 2016-08-13 15:14

Add the below code to the table file you wish to add a date range to:

Code: Select all

function orders_init(&$options, $memberInfo, &$args){
	$options->FilterPage = 'hooks/orders_filter.php';
		return TRUE;
		
	}

... then the file filter will be displayed as follows:

Code: Select all

<link rel="stylesheet" href="resources/bootstrap-datepicker/css/bootstrap-datepicker3.min.css">
<script src="resources/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>

<div class="page-header"><h1><img src="resources/table_icons/cash_register.png"> Search orders</h1></div>

<div style="margin-top: 20px;">
	Show orders placed between
	<input type="hidden" name="FilterField[1]" value="4">
	<input type="hidden" name="FilterOperator[1]" value="greater-than-or-equal-to">
	<input type="text" name="FilterValue[1]" id="from-date" value="<?php echo htmlspecialchars($FilterValue[1]); ?>" size="10">
	
	and
	<input type="hidden" name="FilterAnd[2]" value="and">
	
	<input type="hidden" name="FilterField[2]" value="4">
	<input type="hidden" name="FilterOperator[2]" value="less-than-or-equal-to">
	<input type="text" name="FilterValue[2]" id="to-date" value="<?php echo htmlspecialchars($FilterValue[2]); ?>" size="10">
</div>

<div style="margin-top: 10px;"><button class="btn btn-success btn-lg">Apply</button></div>

<script>
	$j(function(){
		$j('#from-date, #to-date').datepicker({
			autoclose: true,
			format: 'mm/dd/yyyy',
			orientation: 'top'
		});
		
		$j('#from-date').change(function(){
			$j('#to-date').datepicker('setStartDate', $j('#from-date').val());
			
			var df = new Date($j('#from-date').datepicker('getDate'));
			df.setMonth(df.getMonth() + 1);
			$j('#to-date').datepicker('setDate', df);
		});
	})
</script>

<style>
	#from-date, #to-date{ display: inline !important; }
</style>
The above code and many other tips and tricks are explained in detail in the online course on customizing AppGini at https://www.udemy.com/customizing-appgi ... ode=TENOFF.

Post Reply