how to detect a certain date in a dg table column
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: how to detect a certain date in a dg table column
Sorry Stam, I wrote before I read your piece. I'll try it now..
Re: how to detect a certain date in a dg table column
???
Yes, I know, but I used "tdate" in MY example.
Get the same result if I change my example to use "reviewDate"!
So what's wrong with your syntax?
Re: how to detect a certain date in a dg table column
Hi CAsba,
with my script add this to the last IF THEN...
Best
Klaus
with my script add this to the last IF THEN...
Code: Select all
...
## NOW check if we had found something and take action if yes:
if tFound = TRUE then
## tKey = the INDEX of the array with the found date
set the dghilitedIndexes of grp "your dg here..." to tKey
## tCompleteRow is an array with the content of the found row
## do your thing
end if
...
Klaus
Re: how to detect a certain date in a dg table column
Thanks again, Klaus, tested it and works. Splendid !
Re: how to detect a certain date in a dg table column
You are experienced enough to point out if I have made an error in my syntax, I'm not seeing it although I did write this off the top of my head and there may be a typo or some silly error. However, vague insinuations don't help.
The code is uncomplicated and hard to get wrong. It's fewer lines than writing a loop and certainly less processor intensive.
As to highlighting the row, that's fine until there are enough rows that can't be all displayed - then you have to actively scroll to it, exactly like I mentioned above. If you have 200 rows you'd have take into account the found line, the line height and set the dgVScroll appropriately.
By and large I also try to avoid spoon-feeding the full code to people learning. For obvious reasons... but I see this is needed, especially since even you seem to find some kind of fault here.
Whenever I write a handler, I make it as generalisable as possible so it can be re-used for other cards/stacks/projects.
This is a small handler (excluding comments and variable declarations, it is 8 lines of code), it will work for any situation where you want to search any datagrid column for a piece of data and hilite the row; this should reside in the stack script so it's accessible to all cards:
Code: Select all
command hiliteRow pFilter, pColumn, pDataGrid
# pFilter = text to search for, pColumn is the column to search in
# pDataGrid = the _LONG ID_ of the datagrid to search
local tArray, tKeys
put the dgData of pDataGrid into tArray
filter elements of tArray where each[pColumn] = pFilter
if tArray is empty then
set the dgHilitedIndexes of pDataGrid to empty
exit hiliteRow
end if
put replaceText(the keys of tArray, "\R", comma) into tKeys // "\R" is regex for CR, LF or CRLF
set the dgHilitedIndexes of pDataGrid to tKeys
end hiliteRow
Code: Select all
hiliteRow <the text to search for>, <column name>, <the long id of the datagrid to search>
Code: Select all
hiliteRow the long date, "reviewDate", the long id of group "datagrid 1"
I can guarantee you this works exactly as advertised. If you think there is a fault, check spelling....
Last edited by stam on Wed Sep 13, 2023 3:02 pm, edited 2 times in total.
Re: how to detect a certain date in a dg table column
Yes, sorry, my fault, must have been a typo in my script.
Works fine now!
Works fine now!
Re: how to detect a certain date in a dg table column
More generally this code can be changed to search for anything that contains the text searched for in the specified column, eg searching for "October" in the long date. just change the line
to
Any comparison operator can be used in place of "=" making it extremely flexible and easy to maintain...
'each' makes this possible in a single line and is one of those things that the majority of other languages lack and makes it seem like magic...
Code: Select all
filter elements of tArray where each[pColumn] = pFilter
Code: Select all
filter elements of tArray where each[pColumn] contains pFilter
'each' makes this possible in a single line and is one of those things that the majority of other languages lack and makes it seem like magic...
Re: how to detect a certain date in a dg table column
Hi guys,
Firstly, the DG only holds two dates, and these are entered as long date and abbrev date, which effectively differentiates them, so searching the dgtext is not going to get a spurious date.
An update..I was still getting problems trying to hilite the line (in order to extract further data from the line, name of customer, and lastinvoice).
Then I hit on this code that obviates the need to hilite the line..
It works !
Thanks for all your help and interesting insights.
Firstly, the DG only holds two dates, and these are entered as long date and abbrev date, which effectively differentiates them, so searching the dgtext is not going to get a spurious date.
An update..I was still getting problems trying to hilite the line (in order to extract further data from the line, name of customer, and lastinvoice).
Then I hit on this code that obviates the need to hilite the line..
Code: Select all
if the dgtext of grp "Datagrid 1" of cd "custlist" contains the long system date then
put the dgdata of grp "datagrid 1" of cd "custlist" into tData
put the keys of tData into tKeys
put the long system date into tDate
repeat for each line tKey in tKeys
if tData[tKey]["ReviewDate"] = tDate then
put tData[tKey]["Name of customer"] into fld "fbizname"
put tData[tKey]["Lastinvoice"] into fld "flastinvoice"
exit repeat
end if
end repeat
end if
Thanks for all your help and interesting insights.