Polygrid : Property value is not a array

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
czech003
Posts: 2
Joined: Sun Apr 26, 2015 3:25 pm

Polygrid : Property value is not a array

Post by czech003 » Sun Nov 03, 2024 3:54 am

Good evening,

I am having a issue with setting pgData of the polygrid with a filtered array.
I am getting an error message that the value is not an array.
When I check the array is filtered correctly.
When I check the variable is still an array and when I use the answer message before setting the pgData I do get the correct answer.

The code is as follows:

command recipeSearch tSearch
put kittingItems into tKittingItems
if tSearch is empty then
set the pgData of widget "Recipes" of card "KittingItems" of me to kittingItems. -- this works as expected
else
filter elements of tKittingItems where each["itemDesc"] contains tSearch into tFiltered -- I checked and the array is correctly filtered

set the pgData of widget "Recipes" of card "KittingItems" of me to tFiltered. --I get an error here.

end if
end recipeSearch

I don't know what I am missing.

Thanks,
Markus

stam
Posts: 3089
Joined: Sun Jun 04, 2006 9:39 pm

Re: Polygrid : Property value is not a array

Post by stam » Sun Nov 03, 2024 4:32 am

Hi,
I think PG is a bit fussy with its array data.

Not sure what your array looks like but needs to be
1. Numerically keyed
2. Numerical index needs to start at 1
3. No gaps in numerical indexes ( ie 1,2,3,4,5, not 2,4,5)

Ie it should look like this:

Code: Select all

PgData[1][data or sub array here ]
PgData[2][data or sub array here ]
PgData[3][data or sub array here ]
…
PgData[n][data or sub array here ]
Data grid is much more permissive that way, it just needs the indexes to be numerical, but in my experience, PG is a lot fussier about this.

Maybe that’s your issue?
I have a vague recollection this also affected me previously and I now rarely use PG because although it’s nice and simple, it’s just too constrained for my needs in many cases…DG isn’t as flashy but it does everything I need it to without headaches…

In your case as you are using filter without re-indexing the resultant array, PG is guaranteed to choke on that…

When I previously used PG with filtered arrays, I had to
1. Store the full array as a custom prop so it wasn’t lost
2. Store the index of the primal element filtered within the filtered element itself so I could reference the full array by the original index
3. Re-serialise the filtered array to start from 1 and be in sequence.

Data grid doesn’t need any of this of course, you can just assign the filtered array without worrying about indexes…

PS

Code: Select all

Please use code tags when showing code
This is the </> button above or
By surrounding code with [ code] [ /code] tags (spaces added to stop these from showing as code)

czech003
Posts: 2
Joined: Sun Apr 26, 2015 3:25 pm

Re: Polygrid : Property value is not a array

Post by czech003 » Sun Nov 03, 2024 3:30 pm

Thank you for your insight on this.

I had to re-index the filtered array and now the code works as expected.
My data is not very large. If it was I think Datagrid would be the way to go.
Also thanks for making me aware of the code tag button.

Code: Select all

command recipeSearch tSearch
   put kittingItems into tKittingItems
   if tSearch is empty then 
      set the pgData of widget "Recipes" of card "KittingItems" to kittingItems
   else
      filter elements of tKittingItems where each["itemDesc"] contains tSearch into tFiltered
      put 0 into tcount
      put empty into xkittingItems
      repeat for each key tkey in tFiltered
         add 1 to tcount
         put tFiltered[tkey][itemNo] into xkittingItems[tcount][itemNo]
         put tFiltered[tkey][remark] into xkittingItems[tcount][remark]
         put tFiltered[tkey][kitNomber] into xkittingItems[tcount][kitNomber]
         put tFiltered[tkey][itemDesc] into xkittingItems[tcount][itemDesc]
      end repeat
      set the pgData of widget "Recipes" of card "KittingItems" to xkittingItems
      
   end if
   
end recipeSearch

Sincerely,
Markus

stam
Posts: 3089
Joined: Sun Jun 04, 2006 9:39 pm

Re: Polygrid : Property value is not a array

Post by stam » Mon Nov 04, 2024 10:01 am

Yeah that's what I had to do as well.
Because I use filter quite a lot with tables/listboxes and need to keep a reference to the original array so I can update a database or some such, I also add a line to the repeat loop to log the original key in the master array, prior to filtering, like

Code: Select all

put tFiltered[tkey] into xkittingItems[tOriginalKey]
If changes are made, I put the equivalent of xkittingItems[tCount] into tKittingItems[tOriginalCount] if that makes sense...

Anyway glad it worked for you ;)
Stam

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

Re: Polygrid : Property value is not a array

Post by SparkOut » Mon Nov 04, 2024 3:53 pm

stam wrote:
Mon Nov 04, 2024 10:01 am
tFiltered[tkey] If changes are made, I put the equivalent of xkittingItems[tCount] into tKittingItems[tOriginalCount] if that makes sense..
It makes sense if you read it properly, and not as I did and had a mental image of kittens learning to knit snd counting stitches!

Post Reply