hiding 1st column of table field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: hiding 1st column of table field

Post by marksmithhfx » Fri Dec 02, 2022 12:05 pm

jacque wrote:
Wed Nov 30, 2022 6:33 pm
One more way would be to use metadata, which is a way to store info in text which is not visible to the user. After the array is combined to text, set the metadata of each line to the key and then delete the key from the front of the line. You can reset the data by sorting on the metadata of each line.
Thanks Jacque, I hadn't investigated metadata before so this is another example (along with using a DG) to try. Currently preoccupied with the challenges of getting the app into the App Store for testing. The final hurdle is related to sandboxing but that's a whole different topic which I will post a separate question about on the forum.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: hiding 1st column of table field

Post by marksmithhfx » Fri Dec 02, 2022 12:31 pm

dunbarx wrote:
Wed Nov 30, 2022 7:05 pm
So many cool workarounds.

But all of them seem to me to address a problem that should not exist. Mark, what about that rethinking thing? :wink:

Craig
Hi Craig, the obvious solution is to just drop the row and dispense with a "Reset" option. I am already considering an "Undo" for the last action taken, so that would be another solution. But even there, having access to the original table order might be valuable (and putting the array into a custom property might be just the ticket).

Secondarily there are options from Paul, Jacque and others to try a data grid or use metadata. Just for the learning opportunity I'll probably do both and make comparisons to the current solution.

BTW, as I mentioned previously I submitted a bug report. The response was this is a long standing bug with a history going back to 2011 (and we will update you when it changes). So, the many workarounds discussed here are probably quite valuable 😊

And thanks again to everyone for the discussion. I have certainly found it very useful.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: hiding 1st column of table field

Post by jiml » Sat Dec 03, 2022 11:27 pm

I am trying to hide the 1st column of a table field
Lots of suggestions. Here's one, which may have been suggested already.
It is boneheadedly simple.

Code: Select all

go url "https://netrin.on-rev.com/misc/HideColumnOne.livecode"
Jim Lambert

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: hiding 1st column of table field

Post by marksmithhfx » Sun Dec 04, 2022 3:37 pm

jiml wrote:
Sat Dec 03, 2022 11:27 pm
I am trying to hide the 1st column of a table field
Lots of suggestions. Here's one, which may have been suggested already.
It is boneheadedly simple.

Code: Select all

go url "https://netrin.on-rev.com/misc/HideColumnOne.livecode"
Jim Lambert
Jim, very clever...although it made this bonehead really hurt trying to figure out what you were doing 😆. Let me ask you this, are you creating a whole new "viewing port" over the underlying table, or are you just creating a custom scroll bar for the table that scrolls from column 2 to N, or something else?

Cheers,
Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: hiding 1st column of table field

Post by stam » Sun Dec 04, 2022 5:29 pm

Out of curiosity I tried the solution as well - on first glance it works well. After tinkering however I managed to break it, so the left side of the table (presumably the previously hidden column1) now appears as blank but extends the table to the left with blank space.

I'll be honest, I didn't look into it more because there is a much simpler solution to this issue (the DG), and deleted it - so can't really tell you what happened and what I did. What this tells me though is that it needs to be managed with care as it didn't take much for me to break it...

S.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: hiding 1st column of table field

Post by dunbarx » Sun Dec 04, 2022 5:54 pm

Stam implies that all this is adorable, but essentially wrong-headed; the DG is the answer because it requires no kludging. This assuming that the "hidden" column 1 is going to have to be, just because.

I still think there is another (not necessarily a better) way, to rethink from square one.

Craig

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: hiding 1st column of table field

Post by jiml » Sun Dec 04, 2022 7:20 pm

are you creating a whole new "viewing port" over the underlying table, or are you just creating a custom scroll bar for the table that scrolls from column 2 to N, or something else?
No hidden double table is used.
It's just a single table grouped and shifted to the left so that column 1 is out of view.
There is a horizontal scrollbar in the group which replaces the field's own horizontal scrollbar. This grouped scrollbar assures that column 1 never scrolls into view.
The vertical scrollbar is the field's own scrollbar.
Very simple. No need for hidden fields, arrays or whatever.

Of course, this is not a generalized solution as it can only be used to hide the first (or last) column. It won't work if you want to hide, say, column four.

JimL

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: hiding 1st column of table field

Post by stam » Sun Dec 04, 2022 8:03 pm

That’s a clever and inspired hack Jim - a group that is shifted and custom scroll bar - I guess I must have ungrouped or done something to the group to break it.

Still wondering if this is more sustainable and if is truly worth the effort. I mean we’ve now left ”simplicity” long behind, how much more complex does the hack/workaround m need to be to be considered more difficult than just not creating a column in a data grid?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: hiding 1st column of table field

Post by dunbarx » Sun Dec 04, 2022 9:49 pm

Of course, this is not a generalized solution as it can only be used to hide the first (or last) column. It won't work if you want to hide, say, column four.
In fact, as mentioned a few pages above, LC supports a 0-width "interior" column, simply by setting the tabstops property. To hide column 4::
50,100,150,150,200,200,250
It just does not quite support hiding column 1 that way.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: hiding 1st column of table field

Post by jacque » Sun Dec 04, 2022 10:04 pm

As long as we're throwing ideas around, this may help someone, someday. I create a list of 552 lines using the colornames. The script assigns metadata to each line, and then sorts it by the metadata. I first started out by creating a custom sort function but that took too long (1.5 seconds, vs 1.5 milliseconds by not touching the field.)

Here's what I came up with:

Code: Select all

constant kTag = "<p metadata=[[k]]>[[tText]]</p>"

on makeTable
  put the colornames into tData -- 552 lines
  split tData by cr -- get a numbered array
  repeat for each key k in tData
    put tData[k] into tText
    put merge(kTag) & cr after tList
  end repeat
  set the htmltext of fld 1 to sortFld(tList)
end makeTable

function sortFld pList
  set the itemDel to "="
  sort pList numeric by trueword 1 of item 2 of each
  return pList
end sortFld
Edit: If you store the sorted htmltext in a custom property, you could reset just by setting the htmltext of the field to the property.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: hiding 1st column of table field

Post by marksmithhfx » Mon Dec 05, 2022 2:17 pm

jacque wrote:
Sun Dec 04, 2022 10:04 pm
As long as we're throwing ideas around, this may help someone, someday. I create a list of 552 lines using the colornames. The script assigns metadata to each line, and then sorts it by the metadata. I first started out by creating a custom sort function but that took too long (1.5 seconds, vs 1.5 milliseconds by not touching the field.)
Jacque, brilliant and thank you for posting that. It was so similar in structure to what I was already doing that I was able to implement it quite quickly...

Code: Select all

constant kTag = "<p arrayKey=[[k]]>[[tText]]</p>" -- Jacque
repeat for each key k in gUserdefinedFolderArray
   put gUserdefinedFolderArray[k] into tText -- the array content for key k
   put merge(kTag) & cr after tList -- k and tText are  merged into an html string (see constant kTag)
end repeat
set the htmlText of field "userDefinedBookmarkFolders" to sortText(tList)

function sortText pList -- Jacque
   -- sorts a list of html strings by the embedded key value in each
   set the itemDel to "="
   sort pList numeric by item 2 of each
   set the uOriginalList of this stack to pList
   return pList
end sortText
It worked perfectly, did not require any kludgy "hide in column 2000" (as I think someone here described it 😂) and I even implemented your suggested reset by storing the sorted list in a custom property. All worked perfectly. However, since I've not worked with htmlText or merge (what an amazing command that is) I have a question.

As you may have noticed, I changed some of the text in the constant from "metadata" to "arrayKey" to make it more transparent what was being stored and it worked fine. I even experimented and changed it to "arrayKey and anything else I want" and it still worked fine. So I take it that when LC parses the htmlText it just ignores everything between <p and > and you can put whatever you want in there? Although important for us as we are using the k term to sort the array after delimiting on "="...

Code: Select all

sort pList numeric by item 2 of each

It was also invisibly fast on the table I was displaying (169 rows). Thanks again, I'm sure that technique could come in handy in other places as well.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: hiding 1st column of table field

Post by bn » Mon Dec 05, 2022 3:36 pm

Hi Mark,

Please be careful. The word "metadata" denotes a valid property of a text chunk of a field. The word "arrayKey" is not a valid property and is eliminated from the htlmText of a field once you set it.

Jacque's use of "metadata" results in the fields htmlText in
<p metadata="1">AliceBlue</p>
Your use of "arrayKey" results in
<p>AliceBlue</p>
This means that you can not sort the content of the field according to the content of the metadata of the field once you have set the htmlText using your arrayKey.

Since you set a custom property with the sorted raw htmlText

Code: Select all

set the uOriginalList of this stack to pList
You will not notice the difference if you reset the sort order by using custom property uOriginalList.

But the beauty of Jaque's function sortText pList is that you can use it anytime later to sort the field (provided you pass it the htmlText of the field) and it will restore the original sort order provided it contains the tag "metadata" and the sort number. (Which is lost when you use "arrayKey" instead.

Kind regards
Bernd

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: hiding 1st column of table field

Post by jacque » Mon Dec 05, 2022 7:36 pm

Bernd explained it very well. Metadata can be used for many things since it's a valid LC tag. I've used it to show an explanatory tooltip when clicking or hovering over a word, for example. The info can be used for anything and the user never sees it. But it does have to exist in the htmltext of the field.

The replacement works for you because you're parsing a plain text string but wouldn't work for any other use.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: hiding 1st column of table field

Post by marksmithhfx » Mon Dec 05, 2022 9:00 pm

jacque wrote:
Mon Dec 05, 2022 7:36 pm
Bernd explained it very well. Metadata can be used for many things since it's a valid LC tag. I've used it to show an explanatory tooltip when clicking or hovering over a word, for example. The info can be used for anything and the user never sees it. But it does have to exist in the htmltext of the field.

The replacement works for you because you're parsing a plain text string but wouldn't work for any other use.
Thanks Jacque. It's a very useful technique to know about.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: hiding 1st column of table field

Post by jiml » Mon Dec 05, 2022 10:19 pm

In fact, as mentioned a few pages above, LC supports a 0-width "interior" column, simply by setting the tabstops property. To hide column 4::
50,100,150,150,200,200,250
It just does not quite support hiding column 1 that way.
Actually that tabstops technique does support hiding column 1 or any column.

Code: Select all

go url "https://netrin.on-rev.com/misc/HideAnyColumn.livecode"
Jim Lambert

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”