PDA

View Full Version : using list populate and search together


ABC123

Pat Bremkamp
10-14-2017, 12:09 PM
I'm looking for a way to combine the JSON populate technique with a list search.

We have a history of over 7000 inspections with about 1000 active at any one time. Our app design is to start with a searchable list (in a list control), select a project, then go to other areas to work on it. But, obviously, it takes way to long for a list of 7000 projects to get formatted and listed. We have identified 15 fields that are important to be able to search on, and that search needs to include all jobs in the history. So, we use an Xbasic callback and the "populate" technique to assemble the list in JSON and that is good for up to 500 projects in an acceptable time.
We have hit on the following layout:
44061
In the upper right corner of the pic, the user selects a list type, such as work list, full list, active only, etc. and a record limit, gets the list, then does the search. But, of course, the search only searches the list selected.

I'm looking for a way to combine the list search with the list type and do them together.

Thanks.

Davidk
10-14-2017, 03:51 PM
Is the List Type and Record Limit Server-side?
And the Search Client-Side?

Pat Bremkamp
10-15-2017, 10:30 AM
Yes, the list type and record limit are in an Xbasic callback called in the onChange event of the list type dropdown. I've tried the search both ways...currently set to server side. In the grid there are onSearch and beforeSearch events but I can't find those for the list control.

Davidk
10-15-2017, 11:37 AM
and that search needs to include all jobs in the history

So the search needs to go against the 7,000 inspections.

Do you want to search against 7,000 inspections and then, from those results, select a subset based on List Type and record limit?

Pat Bremkamp
10-15-2017, 12:52 PM
Yes ... you are better at explaining it than I am!

I suppose that I could get the search values using e.dataSubmitted and add them to the sql in the callback, but I was hoping to avoid all that code if Alpha has already done the work.

Pat

Davidk
10-15-2017, 01:25 PM
I think you could use this... have a look at the optional Xbasic function...

https://www.alphasoftware.com/documentation/pages/Ref/Client_Api/UX/list%20object%20methods/searchList%20Method.xml

Since you're using Server-side search, you can include an Xbasic function in .searchList()

Your List Search definition and details are in e.searchDefinition.

All your Search Controls and values... and UX Detail View Controls and values... are in e.tmpl.request.Variables.V.R1.

If you wanted to use State Variables... they'd be found in e.tmpl.request.Variables._state.

Once you're in your Xbasic function... you can adjust the filter in e.searchDefinition... adding in your List Type criteria, row limit, etc... and the rows returned will reflect everything you've set.

Pat Bremkamp
10-17-2017, 09:49 AM
That looks very promising if I can get it to work. Right now, I click the button and nothing appears to happen. It does not appear that the Xbasic function is getting called.

The only place I see the .searchList() function is in the onClick event of the "search" button. So, I set it up this way:
{dialog.object}.getControl('JOBLIST').searchList({searchMode:'serverSide',xbasicAfterFilterCompute:"pickListType"});

Right now, I'm just trying to look at the alpha search definition so I can figure out how to include it. My Xbasic function is
function pickListType as v (e as p)
... some stuff ...
dim alphaFilter[0] as p = e.searchDefinition
dim sql as C
sql = e._state.basesql 'from onDialogInitialize
dim json as c
json = ""
dim js as c
js = ""
dim typePicked as C = alltrim(e.dataSubmitted.listType)
select
case typePicked = "SJ" 'selected job
sql = sql + "WHERE p.PROJECT_NUMBER = :argJobno "
case typePicked = "WL" 'employee work list
sql = sql + "WHERE p.ASSIGNED_EMPLOYEE = :argULINK "
sql = sql + "AND p.CURRENT_ACTIVITY BETWEEN 10 AND 82 "
sql = sql + "ORDER BY p.PROJECT_NUMBER "+sd+" LIMIT :argLimit"
case typePicked = "FL" 'full list
sql = sql + "ORDER BY p.PROJECT_NUMBER "+sd+" LIMIT :argLimit"
case typePicked = "AA" 'all active
sql = sql + "WHERE p.CURRENT_ACTIVITY BETWEEN 10 AND 82 "
sql = sql + "ORDER BY p.PROJECT_NUMBER "+sd+" LIMIT :argLimit"
case typePicked = "CA" 'client can work on these
sql = sql + "WHERE p.CURRENT_ACTIVITY IN (23,70,81) "
sql = sql + "ORDER BY p.PROJECT_NUMBER "+sd+" LIMIT :argLimit"
case typePicked = "AN" 'active and has advise or deficient items
sql = sql + "WHERE p.CURRENT_ACTIVITY BETWEEN 10 AND 82 "
sql = sql + "(SELECT COUNT(*) FROM project_lines l WHERE l.PROJECT_NUMBER = p.PROJECT_NUMBER AND l.LINE_STATUS IN ('Advise','Deficient')) > 0 "
sql = sql + "ORDER BY p.PROJECT_NUMBER "+sd+" LIMIT :argLimit"
case else
hasError = .t.
errorMsg = "Could not change list type"
end select
if hasError = .F.
if cnx.open("::name::nfn")
if cnx.execute(sql,args)
crs = cnx.ResultSet
json = crs.ToJSONObjectSyntax()
json = strtran(json,crlf(),"," + crlf())
json = "[" + rtrim(json,",") + "]"
js = "var lObj={dialog.object}.getControl('JOBLIST');"+crlf()
js = js+"var _data="+json+crlf()
js = js+"lObj.populate(_data);"
cnx.FreeResult()
else
hasError = .T.
errorMsg = "Could not execute query"
end if
cnx.close()
else
hasError = .T.
errorMsg = "Could not connect to the database"
end if
end if
if hasError = .F.
pickListType = js
else
pickListType = "alert(errorMsg);"
end if
end function

Pat Bremkamp
10-23-2017, 03:42 PM
Could not access the Xbasic function for some reason, so I switched the search button to call the callback function, got the search values there, built the where clause, run the sql and it is working.
Pat

Pat Bremkamp
10-24-2017, 09:15 AM
Well duh! That feature is not available until release 4642. I'm not on that release yet!