how to print a line (row) of a dg table

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

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

Re: how to print a line (row) of a dg table

Post by stam » Tue May 14, 2024 5:39 pm

dunbarx wrote:
Tue May 14, 2024 3:15 pm
Klaus, what are you trying to say here?

Set?

Craig
Set a property
Put into a variable
Mixing these is recipe for an unhappy life ;)

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

Re: how to print a line (row) of a dg table

Post by dunbarx » Tue May 14, 2024 10:47 pm

Stam, Klaus.

Yes, I know. :roll:

I was only playing around with the 150 point word "set" in Cossack Pogrom ultra-bold that Klaus posted, trying, I assume, to make his point loud and clear.

Sheesh.

Craig

CAsba
Posts: 381
Joined: Fri Sep 30, 2022 12:11 pm

Re: how to print a line (row) of a dg table

Post by CAsba » Wed May 15, 2024 9:11 pm

Jacque,
Yes it would have to be scrolled. Also, only 10 of the 30+ columns would need to be printed - they would be the only visible columns. Currently I'm putting the extracted line data into fields, and adding blank spaces to the fields according to the number of characters in the fields, to make each line of fields approximate to columns for the fields. Hope that makes sense.

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

Re: how to print a line (row) of a dg table

Post by dunbarx » Wed May 15, 2024 10:29 pm

CAsba.

Your comment:
to make each line of fields approximate to columns for the fields.
Makes me think you have separate fields for each column, and you have ganged those fields side by side to create the whole package. That will work, but is not the best way to do this. So I ask again about using a single table field to do the job.

If not, then is it that you have a field that contains several lines, and the lengths of the contents of those lines are not uniform? But if the field is wide enough to show the longest line, why do you need to pad the others? They will fit.

Why not post a screenshot of what you have? I suspect you are doing a lot more work than you need to.

Craig

CAsba
Posts: 381
Joined: Fri Sep 30, 2022 12:11 pm

Re: how to print a line (row) of a dg table

Post by CAsba » Wed May 15, 2024 11:41 pm

Hi Craig,
I took a look at tablefield, but I was not able to understand it, how to get data into it programmatically. I never heard of it before, (I am a beginner !)

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 136
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: how to print a line (row) of a dg table

Post by bobcole » Thu May 16, 2024 1:03 am

CAsba:
I recommend a report. It is much easier and highly flexible.
The only downside is that you need to write a simple template file (html).

Here is a sample:
sample.jpg
The button "Print Line" will print a report of the items on the line in your web browser.
Sample Report.jpg
The LiveCode program and the report template are included in this zip file.
The code is included in the zip file.
Print Sampler.zip
(9.25 KiB) Downloaded 11 times
Bob

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

Re: how to print a line (row) of a dg table

Post by stam » Thu May 16, 2024 1:25 am

CAsba wrote:
Wed May 15, 2024 11:41 pm
Hi Craig,
I took a look at tablefield, but I was not able to understand it, how to get data into it programmatically. I never heard of it before, (I am a beginner !)
A tableField is just a normal field with the difference that it treats tab-separated-values (TSV) as spreadsheet data.
If data items (ie columns) are separated by a tab, each item will be in its own cell. You can adjust the widths of columns with the tabstops. The end of the row/record is defined by a return, so your cells must not contain a return (not really a problem for your example).
Otherwise pretty much the same as any field…

It’s worth learning as the code for it is simple, although it doesn’t have many features like the data grid it has its uses…

So just put tab-separated data into the field and it will populate…
You can test this easily for example with the dgText of a datagrid since that is in TSV format:

Code: Select all

Put the dgText of group “data grid” into field “myTableField”

CAsba
Posts: 381
Joined: Fri Sep 30, 2022 12:11 pm

Re: how to print a line (row) of a dg table

Post by CAsba » Thu May 16, 2024 9:38 am

Hi Stam,
#Thanks for that. How would I put only SOME of the datagrid columns into the tablefield ?

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

Re: how to print a line (row) of a dg table

Post by dunbarx » Thu May 16, 2024 2:37 pm

CAsba.

The "DGText" from a dataGrid is a tab and return delimited dataSet, just like Excel. A table field is just a LC field with certain properties built to emulate a spreadsheet. So if you simply put the DGText into a table field, it will appear already and properly formatted. The table field has "tabStop" as its main distinguishing property. Though all fields have this, the table field appears as a spreadsheet-like control, and the vertical dividers track the tabStop settings.

Make a table field, and:

Code: Select all

   put "X" & tab & "Y" & tab & "Z" & return & "A" & tab & "B" & tab & "C" into fld "yourTableField"
See? That data appears in the table field just like in a spreadsheet. The tabStops determine the "width" of the columns.

Craig

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

Re: how to print a line (row) of a dg table

Post by dunbarx » Thu May 16, 2024 2:47 pm

CAsba.

What I meant was something like this. In a button script:

Code: Select all

on mouseUp
   put "X" & tab & "Y" & tab & "Z" & return & "A" & tab & "B" & tab & "C" & return & "A" & tab & "S" & tab & "D" into temp
   
   set the itemDel to tab
   repeat for each line tLine in temp  
      put item 2 of tLine & return after columnData
   end repeat
   put columnData into fld 1
end mouseUp
You can see that the second item of each line, which corresponds to the data in the second "column" of your dataSet appears in the field.

Craig

CAsba
Posts: 381
Joined: Fri Sep 30, 2022 12:11 pm

Re: how to print a line (row) of a dg table

Post by CAsba » Thu May 16, 2024 3:02 pm

Thanks for that Craig, but
how do I 'make a tablefield' ?

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

Re: how to print a line (row) of a dg table

Post by stam » Thu May 16, 2024 3:17 pm

CAsba wrote:
Thu May 16, 2024 3:02 pm
Thanks for that Craig, but
how do I 'make a tablefield' ?
tablefield.jpg

CAsba
Posts: 381
Joined: Fri Sep 30, 2022 12:11 pm

Re: how to print a line (row) of a dg table

Post by CAsba » Thu May 16, 2024 4:17 pm

Many thanks Stam

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

Re: how to print a line (row) of a dg table

Post by stam » Thu May 16, 2024 4:33 pm

The image above shows how you can just added to a card as a convenience.
But this is just a normal text field. Any text field can do this, just go to the 'table' section in the property inspector:
Screenshot 2024-05-16 at 16.26.25.png
To adjust the widths of the columns you need to set the tabStops (in the property inspector or by code).
Personally I find tabStops a bit confusing, but look at the documentation in the dictionary.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”