Page 1 of 1

Filter by Date Range

Posted: 2015-04-02 17:15
by primitive_man
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.

Re: Filter by Date Range

Posted: 2015-04-04 22:17
by a.gneady
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 6829 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

Re: Filter by Date Range

Posted: 2015-04-14 19:26
by primitive_man
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?

Re: Filter by Date Range

Posted: 2015-04-15 08:26
by a.gneady
'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.

Re: Filter by Date Range

Posted: 2015-04-17 15:12
by primitive_man
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 6774 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?

Re: Filter by Date Range

Posted: 2015-04-17 15:37
by primitive_man
Sorry... Cancel the above request, got it and thank you for your help yet again, a.gneady

Re: Filter by Date Range

Posted: 2015-04-21 00:48
by a.gneady
You're always welcome :D

Re: Filter by Date Range

Posted: 2016-07-15 12:07
by petrescucld
How can i modify the filter page so that it includes a date range?

thank you!

Re: Filter by Date Range

Posted: 2016-08-13 15:14
by Aya Adel
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.