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

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 » Tue Dec 06, 2022 3:38 am

Jim.

Well, that was easy. Just set the first tabStop to 0.

The problem is that i tried that several different ways, as did others, and we all ended up with a column 1 of a few pixels width. It was not fully hidden.

I am going to get the properties of a test table field and the one in the stack you referred to. Maybe I will find a property setting that goes the whole way.

Watch this space...

Craig

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 » Tue Dec 06, 2022 4:09 am

Well, I cannot wait to hear what others will say.

The difference in the properties came down only to the tabletops themselves. "2,8,8,8" was the setting for the url that Jim posted, and that allowed the first column to be hidden. I swear I tried a number of different tabletop settings, including "0", "0,50" etc.

None of those worked. And so I made another table field and set the tabStops to the one from the post. That worked as well, and when I changed those stops to some of the others, column 1 stayed fully hidden.

After playing around just a little more, LC crashed. I had to abort.

Going to try again...

Craig

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 » Tue Dec 06, 2022 5:36 pm

jiml wrote:
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.
Jim, in your initMe handler add a line

Code: Select all

set the leftMargin of me to 7
which approximates the default for table fields and was the spacing I was looking for. Now try hiding various columns. Column 1 is the only 1 that won't be fully hidden. You can see this effect even more dramatically by setting leftMargin to 20 or more. Again, all columns higher than 1 are hidden completely by setting the tab stop to 0, and only column 1 isn't. I didn't like the visual effect of pushing the text of subsequent columns right up against the column divider (it looks passable when it's a single digit followed by a space, but when pure alpha text it looks very strange indeed). Jacque's solution works very well I think, and is very intriguing (if I had to describe it properly I probably couldn't but you can look up her example a few posts earlier).

Mark

PS here's a link, if this works, to a partial screenshot of the app...

https://www.dropbox.com/s/t6mkxf5elmibe ... m.png?dl=0
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

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 » Tue Dec 06, 2022 6:13 pm

Mark.

I know.

But the stack that Jimi posted sort of actually works. i say sort of, because I do not understand it, and have trouble experimenting with it.

Here is the stack. Back up before using!
HideAnyColumn.livecode.zip
(2.83 KiB) Downloaded 56 times
Craig

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 » Tue Dec 06, 2022 6:47 pm

dunbarx wrote:
Tue Dec 06, 2022 6:13 pm
But the stack that Jimi posted sort of actually works. i say sort of, because I do not understand it, and have trouble experimenting with it.
Hi Craig,

"Actually works" only if you are willing to have your text aligned completely adjacent to the tab stop lines. Aesthetically that was not an option for me. Once you move away from that limitation (set leftMargin > 2) then the hiding doesn't work anymore.

BTW, did the link in my last post work for you? I can't really tell because it is to my own dropbox account.

Mark
Last edited by marksmithhfx on Tue Dec 06, 2022 8:42 pm, edited 1 time in total.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

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 » Tue Dec 06, 2022 8:08 pm

Mark.

I did. I see your data is left justified.

The stack from Jimi is limited by the length of the text it can display. There are issues with the table field that prevent the user from exercising perfect control over it.

I still cannot reliably work with the field from his stack. Setting tabstops is frustrating, since only certain values seem to work reliably, and the amount of text in each "cell" determines how well that goes down.

I also cannot create a stack from scratch that shows a true hidden column 1. I can set the properties of a new table field to the properties of the "base" stack, but that leads to problems as well. I am not really motivated to flesh all that out.

Craig

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

Re: hiding 1st column of table field

Post by stam » Tue Dec 06, 2022 10:10 pm

Here's my suggestion as this has now hit 5 pages and somehow it seems this should have taken less...

Instead of trying to massage the tableField which has ludicrously limited functions for such things, or trying to massage objects into gadgetry that sometimes works, why not massage the data instead?

I mentioned this before but no one bit, so...
- Store the full text in a custom prop of the field in which you want a column hidden. Lets call it uText
- Store the list of columns to hide in a different custom prop of the same field. Lets call it uColumnsToHide (can be more than 1 column)
- Then iterate populating columns in this field with all columns of the source data, except for the columns to hide.

If you want to sort lines, add or delete, do this to uText, then apply then only show the columns not in uColumnsToHide. Any changes to the text in the field (if not adding/deleting/reordering) can be saved directly to uText and if you want to reference a line based on the hidden field, do so from the uText, not the text of the field (the two should be identical except for the hidden columns).

In short, treat uText as an 'invisible table' which you can only see in the properties panel, and the actual field as a mirror to this (except editing the text in the field also updates uText).

Here's what I did in *very* limited testing - I added the scripts below to the script of the target field that is to hide the columns.
To store the data, the columns to hide and to show the text with the columns hidden:

Code: Select all

command setSourceText pText, pColumnsToHide // TSV text, list of cols to hide
    local tTextToShow
    set the uText of me to pText
    set the uColumnsToHide of me to pColumnsToHide
    set the itemDelimiter to tab
    repeat for each line tLine in pText
        repeat with x = 1 to the number of items of tLine
            if x is not in pColumnsToHide then
                put item x of tLine & tab after tTextToShow
            end if
        end repeat
        delete the last char of tTextToShow
        put return after tTextToShow
    end repeat
    set the text of me to tTextToShow
end setSourceText
To update the uText custom prop with the text that is in the field:

Code: Select all

command saveText
    local tText, tColumnsToHide, tHidden
    put the text of me into tText
    put the uColumnsToHide of me into tColumnsToHide
    set the itemdel to tab
    repeat with x = 1 to the number of lines of tText
        repeat for each word tCol in tColumnsToHide
            put tab & item tCol of line x of the uText of me into tHidden
            put tHidden after item tCol-1 of line x of tText 
        end repeat
    end repeat
    set the uText of me to tText
end saveText
To save data automatically to the uText of the field on exiting the field after edits:

Code: Select all

on closeField
   saveText
end closeField
I did not implement add/delete/sort functions - but those should be applied to the uText custom property and then set the text of the field to the uText of the field.

I attach a stack to illustrate - this was a quick back-of-the-evenlope code and it may not work (although it did for me) and almost certainly can be massively optimised further - but I attach it in case this helps.

S.

PS: In the attached stack, clear the text from the bottom field then click "Set" to store the data from the top field, but hiding column 2.
Attachments
hide a column.livecode.zip
(2.72 KiB) Downloaded 55 times

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 » Tue Dec 06, 2022 10:30 pm

Stam.

I did not open your stack, but I am with you in principle. I suggested something similar early on (it does indeed seem like a long time ago...) to use, not the dataSet in a custom property but a separate hidden table field. All work would be done there, and columns two to one million exported as often as needed to the visible one.

One advantage I think that has over using a custom property is that one can make the "main" field visible if any maintenance or new functionality is needed. One can see what is happening right there, and how it looks and feels. Then just hide it again.

Craig

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

Re: hiding 1st column of table field

Post by stam » Tue Dec 06, 2022 11:25 pm

Similar but quite different - one key difference is you can convert *any* table field to this - instead of putting the above into the field script, put it into a behaviour script and then you can assign the behaviour to any table field.

Also, it’s just the one object - you can do the “maintenance” by inspecting the custom prop in the properties inspector or just dump it into a temporary tree widget… admittedly the last two are personal choices, but having this as a behaviour to assign is more helpful in my view….
Last edited by stam on Wed Dec 07, 2022 10:02 pm, edited 1 time in total.

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

Re: hiding 1st column of table field

Post by stam » Wed Dec 07, 2022 2:08 am

OK - so tidied up my solution a bit. No gadgets/tricks/manipulating tabstops/etc.
Just a single, bog-standard table field (much as I hate them ;) ).
All the functionality is in the behaviour script of the table field.

I added some buttons to call the handlers in the behaviour script with some example data.
Start by clicking 'Add source' to populate the field. The column to hide is set at '2' by default, but change this to any number (eg '1'), or list of numbers (eg '2,3') and it will not show these columns when clicking 'add source', or if wanting to change this after the data is loaded then click the "update" button next to the field.

The behaviour is not complete (for example there is no sort function, only deletes the last line, etc) but should be a clear basis to add more handlers as needed - just sort/manipuate the uText custom property of the field and send "hideColumns" to it to update display. You also don't need a second field as you can just display the hidden fields by sending "showHidden" to it.
My preference is to use substacks for behaviours - add this to your stack and assign as behaviour to any table field.

Hope this helps
Stam
------
* Edited as below
Attachments
hide a column.livecode.zip
(3.67 KiB) Downloaded 50 times
hidecolumns.jpg
Last edited by stam on Wed Dec 07, 2022 9:55 pm, edited 2 times in total.

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 » Wed Dec 07, 2022 11:29 am

HI Stam,

Thanks for posting that nice implementation of a behavior script.
Please note that your code to hide columns only works for up to 9 columns. Suppose you have 12 columns and you want to hide column 12 and you put 12 into the field for columns to hide it would hide column 1, 2 and 12. In your sample with 3 columns putting 12 into the field would hide columns 1 and 2.
A glitch like that can be hard to track down.

Kind regards
Bernd

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 » Wed Dec 07, 2022 12:25 pm

stam wrote:
Wed Dec 07, 2022 2:08 am
OK - so tidied up my solution a bit. No gadgets/tricks/manipulating tabstops/etc.
Just a single, bog-standard table field (much as I hate them ;) ).
All the functionality is in the behaviour script of the table field.
Hi Stam,

That looks like a terrific general purpose solution to hiding columns in a table field. For my particular use case it probably is more "kit" than I need. Once the data is loaded into the table any changes are initiated by the user (sorting, drag/drop) so all of the changes are captured in the visible table in real time. Since no changes take place behind the scenes there really is no need to have a separate copy of the data somewhere else and not duplicating data reduces complexity. (He says, noting that I did put a copy of the original sorted list in a custom property, but as Bernd pointed out, if I use "metadata" as the html tag I can just pull the htmlText of the table back out, sort by the metadata field and put it back in (to handle the reset option) and don't need to store it in a separate location). However, I bet for many the example you created will be valuable. I find every exposure to someone else's code is a learning experience, and your solution was no exception. I particularly liked the way you used a behaviour script to generalise your solution to be "reusable". That was a nice touch!

At some point in the future... not till I have this in beta, I will investigate using a different kind of table (I know you hate the table field) to see how the effort and value compares. Probably a DG will work. And there's polygrid in the summer mega bundle. It's actually nice we have so much to choose from. Now, if they would only fix the bug with tabstop = 0 in column 1 😊

All the best,
Mark
Last edited by marksmithhfx on Wed Dec 07, 2022 8:14 pm, edited 1 time in total.
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 » Wed Dec 07, 2022 1:10 pm

bn wrote:
Wed Dec 07, 2022 11:29 am
HI Stam,

Thanks for posting that nice implementation of a behavior script.
Please note that your code to hide columns only works for up to 9 columns. Suppose you have 12 columns and you want to hide column 12 and you put 12 into the field for columns to hide it would hide column 1, 2 and 12. In your sample with 3 columns putting 12 into the field would hide columns 1 and 2.
A glitch like that can be hard to track down.

Kind regards
Bernd
You are as always quite correct Bernd :oops:
I think changing the 'hideColumns' handler in the behaviour script should fix it:

Code: Select all

command hideColumns
    local tTextToShow, tColumnsToHide
    set the itemDelimiter to tab	
    put replaceText(the uColumnsToHide of me, "\,", space) into tColumnsToHide
    repeat for each line tLine in the uText of me
        repeat with x = 1 to the number of items of tLine
            if  wordOffset(x, tColumnsToHide ) = 0 then
                put item x of tLine & tab after tTextToShow
            end if
        end repeat
        delete the last char of tTextToShow
        put return after tTextToShow
    end repeat
    set the text of me to tTextToShow
end hideColumns
@Mark - as I mentioned before a datagrid would have been zero effort to do any/all of this (either not create a column for it or set the column width to zero, so it's easier to show/hide - this code is just an intellectual exercise really. Good luck with the beta!

S.

PS: On quick testing the above handler now seems to work as expected - I updated the stack in my previous post

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 » Wed Dec 07, 2022 2:23 pm

Hi Stam,

"hideColumns" only works reliably if you set the wholeMatches to true.

WholeMatches is dear to me because half of the problems with the Project Browser stem from the fact that it did not include "wholeMatches" when dealing with numeric items. Similar to the problem here. (the wholeMatches thing in Project Browser is fixed in LC 9.6.9 rc2)

Code: Select all

command hideColumns
   local tTextToShow, tColumnsToHide
   put replaceText(the uColumnsToHide of me, "\,", space) into tColumnsToHide
   set the wholeMatches to true -- < added
   repeat for each line tLine in the uText of me
      repeat with x = 1 to the number of items of tLine
         if  wordOffset(x, tColumnsToHide ) = 0 then
            put item x of tLine & tab after tTextToShow
         end if
      end repeat
      delete the last char of tTextToShow
      put return after tTextToShow
   end repeat
   set the text of me to tTextToShow
end hideColumns
Kind regards
Bernd

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

Re: hiding 1st column of table field

Post by stam » Wed Dec 07, 2022 9:54 pm

bn wrote:
Wed Dec 07, 2022 2:23 pm
"hideColumns" only works reliably if you set the wholeMatches to true.

WholeMatches is dear to me because half of the problems with the Project Browser stem from the fact that it did not include "wholeMatches" when dealing with numeric items. Similar to the problem here. (the wholeMatches thing in Project Browser is fixed in LC 9.6.9 rc2)
Thanks for the insight Bernd - it seemed to work exactly as planned as it was, but I hear your warning - and will keep in mind for the future...
Stack above updated with your correct code.

S.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”