Welcome! Log In Create A New Profile

Advanced

Filter a table

Posted by Alan 
Alan
Filter a table
August 06, 2009 08:38PM
Hi guys,

Can anyone tell me where I'm going wrong with this please? I've got a table control showing the contents of a table which has records called 'jobs' inside with a click button above it. A 'job' has two statuses, either 0 or 1. I just want to be able to show ALL jobs OR just the ones where the status is not 1 (Completed). The code I have will hide the Completed ones, but when I press it again does not show ALL the jobs again.

MySelf..Caption=(MySelf..Pushed?"Show Completed Jobs" ELSE "Don't Show Completed Jobs")
IF MySelf..Pushed =True THEN
showcomps=True
HDeactivateFilter(JobSchedules)
HFilter(JobSchedules,COMPLETED,0)
ELSE
showcomps=False
HDeactivateFilter(JobSchedules)
HFilter(JobSchedules,COMPLETED,"COMPLETED >=0" )
END
TableDisplay(TABLE_JobSchedules)
TableSelectPlus(TABLE_JobSchedules, 1)


Many thanks for any help !
Regards
Alan
Piet van Zanten
Re: Filter a table
August 06, 2009 10:07PM
Hi Alan,

MySelf..Caption=(MySelf..Pushed?"Show Completed Jobs" ELSE "Don't Show Completed Jobs")
IF MySelf..Pushed =True THEN
showcomps=True
HDeactivateFilter(JobSchedules)
HFilter(JobSchedules,COMPLETED,0)
ELSE
showcomps=False
HDeactivateFilter(JobSchedules)
// remove this line, hdeactivatefilter will show ALL records HFilter(JobSchedules,COMPLETED,"COMPLETED >=0" )
END
TableDisplay(TABLE_JobSchedules
,taInit // taInit will refresh the table content
TableSelectPlus(TABLE_JobSchedules, 1)

Regards,
Piet
Milton
Re: Filter a table
August 06, 2009 10:09PM
Hi Alan,

I have a similar issue which I resolved this way -

I have a radio button at the top of a table for the user to select one of 3 states



The radio button has the following code -

IF Radio1= 1 THEN
HFilter(HELPDESK,TotalActive,1,1)
END

IF Radio1=2 THEN
HFilter(HELPDESK,TotalCompleted,1,1)
END

IF Radio1=3 THEN
HFilter(HELPDESK,TotalActive,0,1)
END

In this case I have constructed a composite filter key of TOTALACTIVE.

However, I would have been better to not use filtering at all and to simply construct 3 queries to support each of the statuses I wanted to display since this would make my application much faster as I only need to load the records needed for dispaly rather than loading the whole table and then filtering the records. In fact, I will change this now that I have re-looked at it.

In any case, you may wish to consider using queries instead of filters yourself.

HTH

Milton
DW
Re: Filter a table
August 07, 2009 03:39PM
Hello Alan,

I agree with Milton on queries instead of filters that is the power of Windev more then one way to do things.

I do something similar on a lot of my tables but use a combo box with 3 choices:
Active, Inactive, All

//This is a Query with a parameter set on the active status if you want all records skip the parameter and execute the query.

SWITCH COMBO_ActiveStatus
..CASE 1 //Active
.....QRY_Warehouse_Table.Param_Status = 1
..CASE 2 //Inactive
.....QRY_Warehouse_Table.Param_Status = 0
..CASE 3 //All
.....//Do nothing
END

Or if you want to use the filter like Milton.
Switch Radio1
.. Case 1 //Active
..... HFilter(HELPDESK,TotalActive,1,1)
.. Case 2 //Inactive
..... HFilter(HELPDESK,TotalCompleted,1,1)
.. Case 3 //All
..... HFilter(HELPDESK,TotalActive,0,1)
END

Also there is a 3 state checkbox from time to time I use for this purpose.

Just my 2 cents

Dennis W
Alan
Re: Filter a table
August 07, 2009 07:15PM
Ok, thanks for both suggestions, I'll give them a go !
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: