Page 1 of 1
Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 7:37 am
by MichaelBluejay
Since I'm no fan of the Data Grid, I wasn't surprised when I selected some rows and found that the "Copy" command is grayed out, making it impossible for a user to copy data out of the Data Grid and paste into, say, a spreadsheet.
Am I missing something, or is the Data Grid truly this crippled?
If there's no native support, I think solution would be to make a "Copy" button with this code:
Code: Select all
set the clipboardData["text"] to the dgText of grp "myDG"
The good news is that the workaround is a mere single line of code for the whole DG. It does copy the whole DG; if just a selection is needed it gets tricker, but probably still do-able.
Probably there's a way to create my own "Copy" menu item and link it to that script, and also to have it work with Command-C, but I haven't messed with menus yet.
Re: Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 1:39 pm
by dunbarx
Hi.
The DG API has all the things you need to work with columns and lines. You just have to learn it all.
That said, I almost always take the whole dataSet, either with the dgText or dgData, do whatever with it "back in LC", and reload the whole.
Craig
Re: Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 1:49 pm
by Klaus
Unfortunately a DATAGRID is not a (single) native LC object, but a group of groups of groups of groups with fields
and whatnot and a biiiiiiig library to mange all this. Therefore it is a
bit tricky to handle a Datagrid.
For your problem you need to collect the hilited lines of the datagrid first:
Code: Select all
...
put the dgText of grp "myDG" into tData
put the dgHilitedlines of grp "myDG" into tLines
put empty into tDataOfTheSelectedLines
repeat for each item tLine in tLines
put line tLine of tData & CR after tDataOfTheSelectedLines
end repeat
## Get rid of trailing CR
delete char -1 of tDataOfTheSelectedLines
## Done:
set the clipboardData["text"] to tDataOfTheSelectedLines
...
Re: Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 3:50 pm
by FourthWorld
Regardless how the DG is implemented, by its flexible nature decisions about what gets copied and how cannot be made by the implementor, necessarily falling on the developer using it.
DG rows are nearly infinite in the various layouts the object supports. They may include plain text, styled text, images, selection controls, and more, or any combination of those. The representation of such varied object types in clipboard data will be different, depending on the details of the use case.
A row may also include hidden elements, such as IDs, which may or may not be relevant in other contexts where the data may be used. Should we include things the user cannot see? Again, I believe it depends on the specifics of a given DG's usage.
In the absence of a one-size-fits-all solution to these questions, a little scripting such as shown above leaves the developer in the driver's seat to make the most appropriate decisions for the case at hand.
Re: Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 4:53 pm
by bangkok
Only one solution.
download/file.php?id=5272
Datagrids are great.
Re: Copy & paste Data Grid data?!
Posted: Tue Mar 17, 2020 5:37 pm
by FourthWorld
I'm on a phone at the moment. I could email a bookmark to myself for when I get back to the office, download the file, decompress it, launch LiveCode, and open the file to see what it is.
But could you take a moment to at least briefly describe it?
Re: Copy & paste Data Grid data?!
Posted: Wed Mar 18, 2020 1:43 am
by bangkok
FourthWorld wrote: ↑Tue Mar 17, 2020 5:37 pm
But could you take a moment to at least briefly describe it?
It's a stack of "datagrid tips and tricks" that i did.
(in english)
it shows several ways to deal with those wild but useful "beasts".
datagrids are complicated to "grasp" for a beginner. the best way (i believe) is to "show" what they can do. then the learning curve is shorter.
so from time to time, on the forum, i post again the link.
Re: Copy & paste Data Grid data?!
Posted: Wed Mar 18, 2020 2:44 am
by FourthWorld
Super cool. Sounds very useful. Thanks, Bangkok.