NetTalk Central

Author Topic: Filter browse by date  (Read 4750 times)

HPabon

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Filter browse by date
« on: October 17, 2012, 12:20:33 PM »
Hi,

How can I filter a browse by using date control?

TIA

Hector Pabon

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Filter browse by date
« Reply #1 on: October 17, 2012, 09:53:32 PM »
There are a few example that show the "browse on a form" approach.
The one I can think of offhand is DropFilter. This one uses a Form, with a drop field, and a browse field. When the drop changes it "resets" the browse.

the meachnism is reasonably straight-forward.

a) make a (memory) form with as many fields as you like, including the browse field. Let's say you have loc:fromdate and loc:todate.
b) add the browse as a field to the form.
c) In the browse filter set something like;
'fil:date <= ' & p_web.GSV('loc:Todate') & ' and fil:date >= ' & p_web.GSV('log:fromdate')
d) on the form set the "reset" field list (on the client-side tab) for both the date fields. Add the Browse field in here.

So when the date changes the browse is reset.
And the browse filters on the session values from the form.

cheers
Bruce

HPabon

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: Filter browse by date
« Reply #2 on: October 18, 2012, 12:24:50 PM »
Hi Bruce,

any sample with date control handling? I want the user select select the date range.

Regards

Hector

rjolda

  • Sr. Member
  • ****
  • Posts: 329
    • View Profile
    • Email
Re: Filter browse by date
« Reply #3 on: October 18, 2012, 04:40:02 PM »
Hector,
I find it easier to troubleshoot filter problems by replacing the filter with a variable (string).
In the embeds, I then code the variable that will be the filter.  Can then check the variable to make sure that you are getting the filter string that you want.  Then let the browse refresh.  Has been most helpful in trying to sort out long or tricky filter strings!
Ron

HPabon

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: Filter browse by date
« Reply #4 on: October 18, 2012, 07:34:51 PM »
Hi ron,

Are there any calendar control that I can place in a form so the user can select dates?

Hector

Stu

  • Hero Member
  • *****
  • Posts: 510
    • View Profile
    • Email
Re: Filter browse by date
« Reply #5 on: October 18, 2012, 08:33:19 PM »
Hi Hector,

I do this almost everywhere in my system. It works well, is simple, and the interface seems to be something general users are fine with.

Quote
Have just read Bruce's reply fully. Below is just a longer more boring version of what he is saying!

1. Create a memory form (don't forget to turn off the save/cancel button, unless you want a "close" button for mobile).

2. Create two tabs in the memory form, first one named "Search" the second named "Browse". Obviously you don't HAVE to do this, but I find it separates it out interface-wise nicely for the brain.

3. Decide if you need to have a RANGE functionality. So if you are searching on an Invoices browse, for example. You want to have an "Invoiced Date" filter. So you probably want a range (From and To).

4. Assuming you want the range, create a new field in the "Search" tab. Add it as a new local variable, and call it "search:Invoice_Date_Range" and make it a STRING(20). Make the field itself a Radio button. Add a few records straight into the Radio button options. I'd go with (just to get this going) "Today", "This Week", "This Month", "Custom". Save the field. We'll come back to it in a moment.

5. Add another local field, call it "search:Invoice_Date_From". Make it a DATE field. Add the following into the "Hide" condition .. p_web.GSV('search:Invoice_Date_Range')~=<39>Custom<39>. Make sure that it is NOT the last on the line. Make sure it's ticked to "Send new value to server" in the "Client-Side" tab.

6. Add another local (Date) field, call it "search:Invoice_Date_To". Give it the same hide condition as above. Make sure it's ticked to "Send to server" also.

7. Then go back to the Range field. In the Client-Side tab make sure it's ticked to "Send new value to server" AND then add both the From and To date fields into the "Reset" mini-browse.

7.5 Click on the "Server Code" button in the Client-Side tab of the Range field. Add the following code:

Code: [Select]
case p_web.GSV('search:Invoice_Date_Range')
of 'Today'
  p_web.SSV('search:Invoice_Date_From',today())
  p_web.SSV('search:Invoice_Date_To',today())
of 'This Week'
  p_web.SSV('search:Invoice_Date_From',today()-today()%7)
  p_web.SSV('search:Invoice_Date_To',today()-today()%7+6)
of 'This Month'
  p_web.SSV('search:Invoice_Date_From',date(month(today()),1,year(today())))
  p_web.SSV('search:Invoice_Date_To',date(month(today())+1,1,year(today()))-1)
of 'Custom'
  ! you don't really do anything here at all
end

8. Now we are ALMOST done with the search form.

9. Go into the "Browse" tab you created above and add the browse procedure (as a Procedure type).

10. Now you need to put in some embed code at the START of the form (whenever it loads). I use the first embed within the "Generate Form" embeds, but Bruce will probably send me to the dunce corner. Whatever place you use, use it to put the following code:

Code: [Select]
if ~p_web.IfExistsSessionValue('search:Invoice_Date_Range')
  p_web.SSV('search:Invoice_Date_Range','This Month')
  p_web.SSV('search:Invoice_Date_From',date(month(today()),1,year(today())))
  p_web.SSV('search:Invoice_Date_To',date(month(today())+1,1,year(today()))-1)
end

11. Now save all the way out of the form.

12. In the browse (if you've already created it then cool, otherwise CREATE THE BROWSE!) go to the "Set Filter" embed under the "Before Browse Loop" parent embed.

13. Add the following code:

Code: [Select]
!* Custom Filter *
loc:FilterWas = ''

if (p_web.GSV('search:Invoice_Date_From') > 0)
  loc:FilterWas = 'invrec:Invoiced_Date>='&p_web.GSV('search:Invoice_Date_From')&choose(loc:FilterWas='','',' and '&clip(loc:FilterWas))      !* this &choose bit at the end is just what I put at the end of most custom filter lines to make sure it's getting the right AND/OR structures. There might be brackets involved too, depending on how intense the filter gets. *
end
if (p_web.GSV('search:Invoice_Date_To') > 0)
  loc:FilterWas = 'invrec:Invoiced_Date<='&p_web.GSV('search:Invoice_Date_To')&choose(loc:FilterWas='','',' and '&clip(loc:FilterWas))
end

!* Set Filter *
ThisView{PROP:Filter} = loc:FilterWas

!* Debug filter if you want *
p_web._trace('(<procedure name>, Custom Filter) Filter: '&clip(loc:FilterWas))

14. Save.

15. Compile.

16. Boom.
« Last Edit: October 18, 2012, 08:39:00 PM by Stu »
Cheers,

Stu Andrews

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Filter browse by date
« Reply #6 on: October 18, 2012, 09:41:24 PM »
>> Are there any calendar control that I can place in a form so the user can select dates?

Use the "Date" form-field control. It comes with a date picker, which you can customise in many different ways.
Also, the date field allows the date to be entered pretty much any way you can think of, not just via the date picker, and
not just in the date picture format you specify. For example, even if you usually use D6 (dd/mm/yyyy) the user could type in;

2012/10/19
10/19/2012
19/10/2012
Oct 19
today
tomorrow
next month
next wednesday
n w
3rd friday in nov
and so on.

It's pretty cool.

cheers
Bruce