Alternating Row Colors of a Data Grid

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 12:59 pm

When you select “alternating row colours” of a Data Grid and you scroll the Data Grid the colours of the rows alternate as it scrolls.

Does anyone know how to have the alternate row colours but for these colours to remain fixed as the Data Grid Scrolls?

All the best

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

Re: Alternating Row Colors of a Data Grid

Post by Klaus » Tue Jan 28, 2014 1:16 pm

Hi tellboy,

not sure what you mean?!
You want something like a (not moving) BACKGROUND IMAGE for the datagrid group?


Best

Klaus

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 1:31 pm

Yes, it probably is the background colour but when I tried to fathom the scripting of the Data Grid it seems an image is created for the background colours but I may be wrong.

I currently have the default white/blue for each of the rows and when I use the scroll bar the text scrolls.

The colours of each row is also maintained as you scroll.

So,

If you have the background colours with black text as follows:

row 1 white with black text testRow1
row 2 blue with black text testRow2
row 3 white with black text testRow3 etc.

When I scroll I want

row 1 to remain white but with black text testRow2
row 2 to remain blue but with black text testRow3

and similarly when I scroll in the other direction.

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

Re: Alternating Row Colors of a Data Grid

Post by Klaus » Tue Jan 28, 2014 1:58 pm

Hi tellboy,

hm, still no idea what exactly you want to achieve, but whatever this is:
1. it is not possible out of the box with the build-in means of the datagrid
2. this will require HEAVY scripting to make it work your way.


Best

Klaus

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 3:11 pm

I will try to describe it again.

I want each row of the Data Grid to always be the same colour.

The Data Grid has 20 rows

Odd rows always white
Even rows always blue

Text always black

The row colour should stay the same Irrespective of the scroll position.

So rows 1,3,5,7,9,11,13,15,17,19 will always have a colour of white
and rows 2,4,6,8,10,12,14,16,18,20 will always have a colour of blue

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

Re: Alternating Row Colors of a Data Grid

Post by Klaus » Tue Jan 28, 2014 3:23 pm

tellboy wrote:...
So rows 1,3,5,7,9,11,13,15,17,19 will always have a colour of white
and rows 2,4,6,8,10,12,14,16,18,20 will always have a colour of blue
Hm, that's exactly what “alternating row colours” does!
The color of each row does not change during scrolling!

But maybe I still don't get it 8)

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

Re: Alternating Row Colors of a Data Grid

Post by dunbarx » Tue Jan 28, 2014 3:35 pm

Hi.

Saw this on the use list. I replied that I did not think there was a native way to do it, but that you can:

set the dgProp["alternate row colors"] of grp "yourDG" to "false"

and then overlay a group of properly sized, colored, blended buttons onto the DG that will stay put while you scroll. A kluge, but should work fine.

Craig Newman

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

Re: Alternating Row Colors of a Data Grid

Post by jacque » Tue Jan 28, 2014 4:58 pm

Does it have to be a datagrid? Because you can do this with a regular field that overlays a carefully sized image. It would be similar to. Craig's approach only a little easier.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 6:01 pm

dunbarx wrote:and then overlay a group of properly sized, colored, blended buttons onto the DG that will stay put while you scroll. A kluge, but should work fine.
I have experimented with this solution for a short while but with a blend it mixes with the underlying colour which in this case is firstly blue and then white as you scroll. You therefore see a flickering blended colour as you scroll, unless I have misunderstood your suggestion. Also this would make life difficult when selecting or editing the text of a table cell.

I would have thought it possible to adjust the scripts behind the scenes of the data grid to achieve what I am after.

Hopefully someone will chime in with an answer.

Thanks

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

Re: Alternating Row Colors of a Data Grid

Post by dunbarx » Tue Jan 28, 2014 6:39 pm

Hi.

Underlying color? I suggested that the DG first be cleared of such things, so it should be white overall.

As to the selection of the "cells" or rows in the underlying DG, you have a point. This can be scripted as well, I think, by knowing the clickLoc and fooling around a bit, but all of a sudden, though I am sure doable, it is more work.

How important, I guess, is this static alternating color thingie?

Craig

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 7:11 pm

tellboy wrote:How important, I guess, is this static alternating color thingie?
Well not essential but my concern with Data Grid is the smoothness or lack of when scrolling when compared to OSX native tables.

The scrolling of the alternating colours does affect your concentration when scrolling through data to find some text when you have a flickering effect as you scroll.

I could have a plain or white colour but then lose the alternating colour benefit of focusing your eye across a row of data.

Hopefully someone will advise how to adjust the Data Grid scripts.

I will be experimenting myself and hopefully can find out how to adjust the scripts.

All the best

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: Alternating Row Colors of a Data Grid

Post by tellboy » Tue Jan 28, 2014 8:24 pm

Well,

I seem to have found it in the Data Grid script. It seems to be located in this part of the script.

Code: Select all

private command _table.DrawWithProperties pSetVScrollTo, pForceRefresh
    ## We only scroll by entire records so if any scrolling is supposed to occur then
    ## start 1 higher
    if pSetVScrollTo > 0 then add 1 to sTableObjectsA["base sequence for visible controls"]
    
    _table.DrawControlsInRealTime pForceRefresh
    if sTableObjectsA["base sequence for visible controls"] mod 2 is kAlternatingRowModValue then
        --set the top of graphic "dgAlternatingRows" of me to the top of group "dgAlternatingRowsMask" of me - sControlHeights  
    else
        set the top of graphic "dgAlternatingRows" of me to the top of group "dgAlternatingRowsMask" of me
    end if
end _table.DrawWithProperties
The code commented out seems to do the trick and does not on the face of it affect anything else.

Code: Select all

--set the top of graphic "dgAlternatingRows" of me to the top of group "dgAlternatingRowsMask" of me - sControlHeights  

All the best

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

Re: Alternating Row Colors of a Data Grid

Post by dunbarx » Tue Jan 28, 2014 11:13 pm

Oooh.

Bravo.

The very complexity of the DG, that is, there is a built-in alternate row color object, can be located so that it "untracks" the integral scroll value.

Craig

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

Re: Alternating Row Colors of a Data Grid

Post by Klaus » Wed Jan 29, 2014 5:24 pm

WOW! Cool finding!

But I still have no idea how that might look :D

Post Reply

Return to “Talking LiveCode”