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

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

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

Post by CAsba » Mon May 13, 2024 10:42 am

Hi all,
Is it possible to print a dg, line by line (some lines only, according to script). This is to create a report. I tried putting the lines in a field, but that did not maintain the column widths, they being dependent on the text width of the column content.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9743
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 » Mon May 13, 2024 2:03 pm

CAsba.

If you get the "dgText" of your dataGrid, you have the entirety of its contents in a return delimited list. Just take that to your printer.

Craig

stam
Posts: 2741
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 » Mon May 13, 2024 4:38 pm

My practice with any any kind of list (tableField, data grid, polygrid, etc) is to store the full data set in a custom property of the object in question.

This allows me to filter the list to only show the records I'm looking for (I guess in your case the lines you want to print) and and having the full data set in the custom property allows me to simply restore the full grid when filtering is no longer needed.

This may be one way you could approach this...

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

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

Post by CAsba » Mon May 13, 2024 5:02 pm

Hi Stam, that's what I've done, but the resulting text is a mess, as it doesn't show the text in columns, as, depending on the width of text in each column of the dg, the lines are too messy to present to the user. I was looking for a way to keep each dataset in a column in the field.
Hi Craig, as above and ALL the data is not required.

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

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

Post by CAsba » Mon May 13, 2024 5:10 pm

Hi all,
I tried

Code: Select all

put the dgProp["column widths"] of group "DataGrid 3" to 53,100,40,40,50,200,103,40,40,40,20,50,50,50,50,50,50,40,40,40,40,40,10,40,40,40,100,50,16,50,20,20,40,50,40
hoping that the text in col 6, not exceeding a width of 200, would maintain column discipline, but I got an error message
Handler; can't find handler near 'to'
I don't have a clue what the correct syntax would be..

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9743
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 » Mon May 13, 2024 5:13 pm

CAsba.

Place the dgText of the DG into a table field. The dgText is tab and return delimited, and if you adjust the tabStops on the table field appropriately, the whole of the text will display just fine. You will have to live with the visual issues related to widely varying widths of the several tab delimited "items" with your dataSet.

From the table field, you can extract any lines you need, or process the data itself as required.

Craig
Last edited by dunbarx on Mon May 13, 2024 5:18 pm, edited 1 time in total.

stam
Posts: 2741
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 » Mon May 13, 2024 5:13 pm

CAsba wrote:
Mon May 13, 2024 5:02 pm
Hi Stam, that's what I've done, but the resulting text is a mess, as it doesn't show the text in columns, as, depending on the width of text in each column of the dg, the lines are too messy to present to the user. I was looking for a way to keep each dataset in a column in the field.
Hi Craig, as above and ALL the data is not required.
Just so I'm clear - do you mean:
1. the datagrid is shown on screen exactly as you want it printed
2. You print it and you just get jumbled lines?

If that is the case then one way may be to export the dg to an image and print the image instead?

If that's not the case, do you mean you've taken the text from the lines you want to print but are unable to format them accordingly?

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

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

Post by CAsba » Mon May 13, 2024 6:46 pm

Hi Stam,
A bit of background. The db has 30+ columns. I want to print just 10 columns. I only want to print some of the lines, others are not required.
I have succeeded in getting the required lines of just the 10 columns into a field. The problem is that the field output has lines where certain 'columns', that is the data in the column in that particular line, overlaps (or underlaps) the data in previous or subsequent lines. This document is a working stocktake paper that the user will use to record stock levels of the products relating to each line. As it stands, it would be unacceptable to present such an untidy, and most probably error-prone jumble. For instance, expected stock figures and actual stock figures could easily get mixed up. I'm going to try to make ALL the 10 columns wide enough to not be affected by long text strings, in the hope that that will work. Could be a nightmare to do it programmitically, and then reverting back to normal on completion.
Unless you know an easier way...

stam
Posts: 2741
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 » Mon May 13, 2024 7:31 pm

CAsba wrote:
Mon May 13, 2024 6:46 pm
Unless you know an easier way...
OK, so more the last option then...

Do I understand from your last post that you used a tableField and that's what isn't behaving? Or did you just use a normal field?
I presume that data is exported as TSV (ie the dgText)?

I can't see how a tableField wouldn't work with TSV, unless your data had cells with carriage returns in them - that would break the TSV and you'd need to replace them with a different character (eg a semicolon or some such) so that no cell has a carriage return (which signifies end of record).

Trying to maintain correct column spacing without using the features of table field (ie. just a normal field) isn't sustainable I don't think...

Perhaps share your code and some example data?
Stam

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9743
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 » Mon May 13, 2024 8:07 pm

I am with Stam.

Are you using a table field? And are the text properties constant throughout that field? That is, the textSize of one line is not different than any other?

Stam mentions a point, but I assume that if you get the dgText, then you are getting just that, the text of the DG. So there should be no extra frame breaking characters lurking anywhere.

Can you send a screen shot of the table field?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9743
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 » Mon May 13, 2024 8:11 pm

CAsba.

Just something of interest to me. Did you extract the data from certain columns by setting the itemDel to "tab", looping through each line in the dgText and collecting only the same single item in each line? If so, you have come a long way. :wink:

Craig

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Tue May 14, 2024 9:12 am

CAsba wrote:
Mon May 13, 2024 5:10 pm
Hi all,
I tried

Code: Select all

put the dgProp["column widths"] of group "DataGrid 3" to 53,100,40,40,50,200,103,40,40,40,20,50,50,50,50,50,50,40,40,40,40,40,10,40,40,40,100,50,16,50,20,20,40,50,40
hoping that the text in col 6, not exceeding a width of 200, would maintain column discipline, but I got an error message
Handler; can't find handler near 'to'
I don't have a clue what the correct syntax would be..
that needs to be SET!

Code: Select all

SET the dgProp["column widths"] of group "DataGrid 3" to 53,100,40,40,50,200,103,40,40,40,20,50,50,50,50,50,50,40,40,40,40,40,10,40,40,40,100,50,16,50,20,20,40,50,40

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9743
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 3:15 pm

Klaus, what are you trying to say here?

Set?

Craig

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

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

Post by jacque » Tue May 14, 2024 5:18 pm

Can you display the data you need in the datagrid? If so, then I'd just print the card. You can either set up a printing card containing only a datagrid, or easier, just print the card in the rect of the datagrid. If it needs to be scrolled to see everything there's a way to do that too, let us know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Tue May 14, 2024 5:27 pm

dunbarx wrote:
Tue May 14, 2024 3:15 pm
Klaus, what are you trying to say here?
Set?
Craig
Take a look at CAsbas script which threw an error, and mine above!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”