Alpha Video Training
Results 1 to 8 of 8

Thread: Conditionally filter a list

  1. #1
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Conditionally filter a list

    In this list on a UX, records will be filtered by a login variable, clientid. Specifying the filter as Clientid = :CLIENTID works fine. But I would also like to have a super user that can see all records. The filer building box does not have an editor that evaluates the filter, but this certainly does not work.
    if( :CLIENTID = 0 , '', Clientid = :CLIENTID )

    Is there an approach that will let me either filter the list by clientid or not?

    Bill.

  2. #2
    Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,596

    Default Re: Conditionally filter a list

    A couple ways Bill.

    First, you can populate the list from an Xbasic function. I've taken to doing this almost by default these days because people keep asking for more changes, more considerations, more filters. Keep in mind that the JSON generated by Xbasic needs to match the field definitions in the list -- including case sensitivity.

    A second way is to use the onDialogExecute event where you can change the e.tmpl like this:

    Code:
    if eval_valid("MyVariable")
    	if MyVariable <> "0"
    		sqlTemplate = <<%a%
    			CustomQueryHere
    		%a%
    		e.tmpl.page_fields[21].v.LIST1.sql.sqlstatement = sqlTemplate
    	end if
    end if
    You'll need the correct array index and name of course - you can find this by choosing the Xbasic tab at the very very bottom of your UX designer.
    -Steve


  3. #3
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,188

    Default Re: Conditionally filter a list

    Bill, does this list have a detail view associated with it?

  4. #4
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Re: Conditionally filter a list

    Steve, at first blush, populating via xbasic sounds attractive.

    Lee, I'll show my newness to this. I do have an OnDblClick event that opens a UX detail parent-child view of the record. But the list itself does not have a "detail view" does it?

  5. #5
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,188

    Default Re: Conditionally filter a list

    I was hoping you'd say that. There is an easy way to do this. In the list control, you can use the Custom/Xbasic function. It runs before the lists loads.

  6. #6
    Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,596

    Default Re: Conditionally filter a list

    Bill - one of the most popular genies in Alpha is the list building genie. Add a new control, but while still in the Add dialog, click the "List Control - Quick Setup Genie" at the bottom of the dialog. It's not everything, but it's pretty helpful and makes the building of a list control with detail a lot easier.
    -Steve


  7. #7
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Re: Conditionally filter a list

    Thanks guys. Off to explore.

  8. #8
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,575

    Default Re: Conditionally filter a list

    Alpha gives you an easy way of doing this. But I have to make the assumption that your login variable is a session variable. If it's not a session variable then post what it is and how you set it.

    If it is a session variable then, in your List Control, Data Source tab, "Server side beforeQuery event", add the word checkUser. This will be an XBasic function that Alpha will call. If you click the Builder for this event you'll see how you can create it. The function can be named anything you like... I named it checkUser.

    In the XBasic functions section of the UX... add this function... which, except for my code, was created by Alpha.

    Code:
    function checkUser as v (e as p)
    	
    'debug(1)	
    'Fires before the query to retrieve List data is executed. You can use this event to authorize the query
    'If the query is not authorized, it will not return any data
    'The e object that is passed in includes:
    'e.tmpl = UX definition
    'e.sql - the SQL statement that will be executed
    'e.arguments - SQL argument values to be passed to the SQL statement
    'e.listProperties - properties of the List control
    
    'Your code can set these properties:
    'e.authorized - set to .t. or .f.. If you do not set e.authorized, it is assumed to be .t.. If e.authorized = .f., the query will not return any data.
    
    'Your code can modify the SQL and the arguments used in the List query. For example:
    'e.sql = "Select id, firstname, lastname from customers where id = :whatid "
    'e.arguments.add("whatId",23)
    
    if session.clientid = 0 then
    	e.sql = "SELECT PersonId, Clientid, FirstName, MiddleName, LastName, Address1, City, St, Zip, Latitude, Longitude, ChargeAmount, AdjustmentAmount, PaidHereAmount, OnholdAmount, OnholdDate, CurrentBalance, Addr_Quality FROM Person WHERE Clientid IS NOT NULL"
    end if	
    
    
    end function
    My code is the "if" statement. If your session var clientid is 0, then your e.sql statement will include WHERE Clientid IS NOT NULL... which should pick up everything.
    If your clientid is, for example, 12, then your List's SQL Statement will not change. This is assuming your List has the filter Clientid = :CLIENTID

    The nice bit about all this is that there is no extra callback. Your List is going to get data... and we're just taking a quick detour to either change the SQL statement... or not.
    Last edited by Davidk; 05-09-2019 at 05:59 PM.

Similar Threads

  1. Conditionally change column width for only specific rows in a UX LIST control
    By RichCPT in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 09-27-2014, 12:54 AM
  2. UX - List control - "conditionally" refresh data ?
    By cemopolat in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 06-18-2014, 05:26 AM
  3. Set background color of conditionally disable list box in an xdialog
    By Ronald Anusiewicz in forum Alpha Five Version 10 - Desktop Applications
    Replies: 1
    Last Post: 08-28-2011, 10:23 AM
  4. Filter Dropdown list in SEARCH part, based on grid filter
    By lgrupido in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 03-28-2011, 05:05 PM
  5. Date Based dropdown list filter does not filter
    By Steve Bovino in forum Web Application Server v6
    Replies: 17
    Last Post: 10-15-2005, 08:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •