Selecting multiple lines in a datagrid

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting multiple lines in a datagrid

Post by Klaus » Fri Nov 06, 2015 4:45 pm

Hi DavJans,

as the name suggests, "the dghiliteledLines" can ce more than one line!
So this should work:

Code: Select all

...
put the dgHilitedLines of group "DataGrid 1" into theLineS
repeat for each item tLine in tLines
   put the dgDataOfLine[theLine] of group "DataGrid 1" into tData1
  ...
end repeat
...
Hint for speed!
Do NOT access fields inside of a repeat loop!
I you have to, always LOCK SCREEN first, or better collect all data in a variable
and then put the complete variable into the field after the loop!


Best

Klaus

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 5:04 pm

Code: Select all

   put the dgHilitedLines of group "DataGrid 1" into theLineS
repeat for each line tLine in tLines
   put the dgDataOfLine[theLineS] of group "DataGrid 1" into tData1
     put tData1["cert"]  & comma after fld "Field1"
     put tData1["job"] & comma after fld "Field1"
     put tData1["minorpcmkid"] & comma after fld "Field1"
     put tData1["heat"] & comma after fld "Field1"
     put tData1["creationdate"] & cr after fld "Field1"
  end repeat
something like this but not quite I guess? If i select 1 line it works, if more then not so much.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting multiple lines in a datagrid

Post by Klaus » Fri Nov 06, 2015 5:16 pm

I did not write that! Look again at my posting! :D

Hint: repeat for each ?

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Fri Nov 06, 2015 5:44 pm

WHOOPS! I see Klaus already weighed in, deleting my post...

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Selecting multiple lines in a datagrid

Post by Klaus » Fri Nov 06, 2015 5:52 pm

Sorry, made a typo, but the trick is to "repeat for each ITEM" (as I wrote!) :D
Please explain to yourself why your script DOES in fact work if only ONE line is selected!

Do this:
...
put the dgHilitedLines of group "DataGrid 1" into theLineS
repeat for each ITEM tLine in theLineS
put the dgDataOfLine[tLine] of group "DataGrid 1" into tData1
...

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Selecting multiple lines in a datagrid

Post by sritcp » Fri Nov 06, 2015 9:32 pm

Mikey:

I hear that Datagrid is so slow on mobile devices (esp iOS) as to be unusable. What is your experience (since you seem to have used it on mobile)?

Regards,
Sri

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Fri Nov 06, 2015 9:54 pm

Since you don't hear me complaining about it/freaking out about it/threatening to leave LC for some LISP or APL IDE, you can assume that it isn't true. We use DG's in every mobile app, including inventory apps, that can have hundreds of lines, and numerous columns (so they have to scroll both horizontally and vertically).

Having said that, the scrolling can be a PITA, if you want a native scroller. Monte's wrote a free dropTool for a native DG with scroller, but it doesn't lock the header when you scroll, so if you scroll down, the header will disappear. The old version of the same code works better for that, but the performance isn't as good. I use the old version because I want the headers to stay put.

Yes, there are flaws, but, every time we walk into a meeting and everyone else in the meeting has a stack of binders with information from their $3MM ERP system from their AS400 that is old news and took their staff hours to produce, and we walk in with phones and ipads with information that's litterally up-to-the-second, they don't really care if their paper looks pretty of if our apps aren't perfect. They just want to know why their IT department sucks so bad and ours doesn't.

Try it out for yourself. Build a test app with a DG, and prepopulate it with 100 rows or so. Then compare it to your current mobile solution. You might think DG's are just dandy.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 10:09 pm

I would blame the fact that it is Friday but I's me. I cant seem to gather what I'm doing wrong.

Code: Select all

   put the dgHilitedLines of group "DataGrid 1" into theLineS
repeat for each item tLine in tLineS
   put the dgDataOfLine[tLine] of group "DataGrid 1" into tData1
     put tData1["cert"]  & comma after fld "Field1"
     put tData1["job"] & comma after fld "Field1"
     put tData1["minorpcmkid"] & comma after fld "Field1"
     put tData1["heat"] & comma after fld "Field1"
     put tData1["creationdate"] & cr after fld "Field1"
  end repeat
Whatever I did, it wont give me any data at all now, even with only 1 line selected.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Fri Nov 06, 2015 10:20 pm

I'm not trying to be difficult, but have you tried using the debugger to see what the values are as you step through? I don't have time right now to futz with it for you.

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 10:25 pm

Nope you are fine.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 10:32 pm

I got it, thank you all for your help.

here is the code for anyone else that stumbles here with the same question someday.

Code: Select all

put the dgHilitedLines of group "DataGrid 1" into theLineS
repeat for each item tLine in theLineS
   put the dgDataOfLine[tLine] of group "DataGrid 1" into tData1
     put tData1["cert"]  & comma after fld "Field1"
     put tData1["job"] & comma after fld "Field1"
     put tData1["minorpcmkid"] & comma after fld "Field1"
     put tData1["heat"] & comma after fld "Field1"
     put tData1["creationdate"] & cr after fld "Field1"
end repeat
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Selecting multiple lines in a datagrid

Post by Mikey » Fri Nov 06, 2015 10:50 pm

Those look the same to me. What did I miss?

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Selecting multiple lines in a datagrid

Post by sritcp » Fri Nov 06, 2015 11:38 pm

Mikey wrote:..... you can assume that it isn't true. We use DG's in every mobile app, including inventory apps, ...
Just what I wanted to hear! I have been using DG on my Mac for a while. I have 2000 rows and 25-30 columns in the master DG on the main card, and subsets of this data on DGs on subsequent cards, the master data editable from any card. Sometimes it is slow going from card to card (have to update the master each time), but otherwise works well. Naturally, my mobile DG will be much smaller in size (especially columns displayed), but wanted to hear from someone using it in real life.
Having said that, the scrolling can be a PITA, if you want a native scroller.
That was going to be my next question!
What about the DG's built-in scroller (on mobile)? Does that work at all (besides the usability problems due to its narrow size)? If it does, is a workaround possible to make it usable?

As for Monte's tool, you can always put a banner image to replace the header when it has scrolled out of view (as long as you don't try to sort a column), can't you?

Also, how about an external slider (and linking it to the visible lines of DG)? Just throwing some ideas at you.

Thanks for the feedback. I feel much better.

Regards,
Sri

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Selecting multiple lines in a datagrid

Post by DavJans » Fri Nov 06, 2015 11:39 pm

I honestly couldn't tell you, comparing the two posts I don't see a difference, but it works now, and it didn't earlier.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Post Reply