[flexcoders] Re: Data grid vary column sizes

2010-05-26 Thread valdhor
Ok, got it working the way I want.

I decided to use "Letter Gothic Line" font from
http://www.fontparade.com/index.php?page=theme&cat=29 as it looked
better (To my eye) than Monaco.

At the same time as I send my request for data to the server from Flex,
I also send a request for Column Names And Widths. This functions looks
like this (PHP)...

  $ColumnNamesAndWidths = array();
 if($result->num_rows > 0)
 {
 while($resultObject = $result->fetch_object())
 {
 foreach($resultObject as $key=>$value)
 {
 if(!array_key_exists($key,
$ColumnNamesAndWidths))
 {
 $ColumnNamesAndWidths[$key] =
max(strlen($key), strlen($value));
 }
 else // Already have that object in the
array
 {
 $currentWidth = max(strlen($key),
strlen($value));
 if($currentWidth >
$ColumnNamesAndWidths[$key])
 {
 $ColumnNamesAndWidths[$key] =
$currentWidth;
 }
 }
 }
 }
 }

So, now I get an object back in Flex with the names of the columns as
properties and the max number of characters for each column as values.

In Flex, I iterate through this object and create columns from the
properties and set widths from the values...

var myDataGridColumnsArray:Array = new Array();
var ColumnNamesAndWidths:Object = event.result as Object;
for(var columnName:String in ColumnNamesAndWidths)
{
 var currentColumn:DataGridColumn = new DataGridColumn(columnName);
 currentColumn.setStyle("fontFamily", "LetterGothic");
 currentColumn.setStyle("fontSize", 11);
 currentColumn.setStyle("headerStyleName", "myDataGridHeader");
 currentColumn.headerText = columnName;
 currentColumn.width = (ColumnNamesAndWidths[columnName] as int) * 7
+ 10; // Add 10 pixels to make it look better
 currentColumn.dataField = columnName;
 currentColumn.itemRenderer = new ClassFactory(Text);

 myDataGridColumnsArray.push(currentColumn);
}
myDataGrid.columns = myDataGridColumnsArray;


HTH.




Steve

--- In flexcoders@yahoogroups.com, "valdhor"  wrote:
>
> I never found any examples on the web.
>
> I am trying to do this now and have my own strategy which may or may
not be the best. In my case, my Data Grid has a max of around 30 rows -
I don't think my strategy would work for large data sets.
>
> So, what I am thinking is to use a mono-spaced embedded font for the
data grid (I am using Apple's Monaco TrueType font). Seeing as I know
the font size I will be using and each character uses the same width, I
can safely use a simple calculation to get the width of the column. I
send a separate request to the server that returns an object that
contains the max character length for each of the fields. In FLex I
create columns from this object and set the datagrid's columns to this
array.
>
> Once I have this working, I will post an example.
>
>
>
> --- In flexcoders@yahoogroups.com, Alex Harui aharui@ wrote:
> >
> > I don't know of any, but this question has been asked so many times,
there's probably an example if you search the web.
> >
> >
> > On 5/25/10 10:36 AM, "method_air" loudjazz@ wrote:
> >
> >
> >
> >
> >
> >
> > Any 'resize data grid columns to content' code examples?
> >
> > --- In flexcoders@yahoogroups.com
 , Alex Harui  wrote:
> > >
> > > The column has to be the same size for every row, but each column
can have different widths.  It would be rare to set it from the
itemrenderer, usually some other code accesses datagrid.column[i].width.
> > >
> > >
> > > On 5/19/10 11:02 AM, "method_air"  wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > > How do you vary the data grid column widths? Setting the width
property inside the item renderers to different values is not working.
> > >
> > > Thanks,
> > >
> > > Philip
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Alex Harui
> > > Flex SDK Team
> > > Adobe System, Inc.
> > > http://blogs.adobe.com/aharui
> > >
> >
> >
> >
> >
> >
> >
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>



[flexcoders] Re: Data grid vary column sizes

2010-05-26 Thread stephen_anson
following  link looks like what you need.
Another variation is to use TextMetrics to figure out the size of the text.

hth
cheers  Steve Anson

http://groups.google.com/group/flex_india/browse_thread/thread/7b546ff1cf7f94b8?pli=1

--- In flexcoders@yahoogroups.com, "valdhor"  wrote:
>
> I never found any examples on the web.
> 
> I am trying to do this now and have my own strategy which may or may not be 
> the best. In my case, my Data Grid has a max of around 30 rows - I don't 
> think my strategy would work for large data sets.
> 
> So, what I am thinking is to use a mono-spaced embedded font for the data 
> grid (I am using Apple's Monaco TrueType font). Seeing as I know the font 
> size I will be using and each character uses the same width, I can safely use 
> a simple calculation to get the width of the column. I send a separate 
> request to the server that returns an object that contains the max character 
> length for each of the fields. In FLex I create columns from this object and 
> set the datagrid's columns to this array.
> 
> Once I have this working, I will post an example.
> 
> 
> 
> --- In flexcoders@yahoogroups.com, Alex Harui  wrote:
> >
> > I don't know of any, but this question has been asked so many times, 
> > there's probably an example if you search the web.
> > 
> > 
> > On 5/25/10 10:36 AM, "method_air"  wrote:
> > 
> > 
> > 
> > 
> > 
> > 
> > Any 'resize data grid columns to content' code examples?
> > 
> > --- In flexcoders@yahoogroups.com  , 
> > Alex Harui  wrote:
> > >
> > > The column has to be the same size for every row, but each column can 
> > > have different widths.  It would be rare to set it from the itemrenderer, 
> > > usually some other code accesses datagrid.column[i].width.
> > >
> > >
> > > On 5/19/10 11:02 AM, "method_air"  wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > > How do you vary the data grid column widths? Setting the width property 
> > > inside the item renderers to different values is not working.
> > >
> > > Thanks,
> > >
> > > Philip
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Alex Harui
> > > Flex SDK Team
> > > Adobe System, Inc.
> > > http://blogs.adobe.com/aharui
> > >
> > 
> > 
> > 
> > 
> > 
> > 
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>




[flexcoders] Re: Data grid vary column sizes

2010-05-26 Thread valdhor
I never found any examples on the web.

I am trying to do this now and have my own strategy which may or may not be the 
best. In my case, my Data Grid has a max of around 30 rows - I don't think my 
strategy would work for large data sets.

So, what I am thinking is to use a mono-spaced embedded font for the data grid 
(I am using Apple's Monaco TrueType font). Seeing as I know the font size I 
will be using and each character uses the same width, I can safely use a simple 
calculation to get the width of the column. I send a separate request to the 
server that returns an object that contains the max character length for each 
of the fields. In FLex I create columns from this object and set the datagrid's 
columns to this array.

Once I have this working, I will post an example.



--- In flexcoders@yahoogroups.com, Alex Harui  wrote:
>
> I don't know of any, but this question has been asked so many times, there's 
> probably an example if you search the web.
> 
> 
> On 5/25/10 10:36 AM, "method_air"  wrote:
> 
> 
> 
> 
> 
> 
> Any 'resize data grid columns to content' code examples?
> 
> --- In flexcoders@yahoogroups.com  , 
> Alex Harui  wrote:
> >
> > The column has to be the same size for every row, but each column can have 
> > different widths.  It would be rare to set it from the itemrenderer, 
> > usually some other code accesses datagrid.column[i].width.
> >
> >
> > On 5/19/10 11:02 AM, "method_air"  wrote:
> >
> >
> >
> >
> >
> >
> > How do you vary the data grid column widths? Setting the width property 
> > inside the item renderers to different values is not working.
> >
> > Thanks,
> >
> > Philip
> >
> >
> >
> >
> >
> >
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
> 
> 
> 
> 
> 
> 
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>




Re: [flexcoders] Re: Data grid vary column sizes

2010-05-25 Thread Alex Harui
I don’t know of any, but this question has been asked so many times, there’s 
probably an example if you search the web.


On 5/25/10 10:36 AM, "method_air"  wrote:






Any 'resize data grid columns to content' code examples?

--- In flexcoders@yahoogroups.com  , Alex 
Harui  wrote:
>
> The column has to be the same size for every row, but each column can have 
> different widths.  It would be rare to set it from the itemrenderer, usually 
> some other code accesses datagrid.column[i].width.
>
>
> On 5/19/10 11:02 AM, "method_air"  wrote:
>
>
>
>
>
>
> How do you vary the data grid column widths? Setting the width property 
> inside the item renderers to different values is not working.
>
> Thanks,
>
> Philip
>
>
>
>
>
>
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Data grid vary column sizes

2010-05-25 Thread method_air
Any 'resize data grid columns to content' code examples?


--- In flexcoders@yahoogroups.com, Alex Harui  wrote:
>
> The column has to be the same size for every row, but each column can have 
> different widths.  It would be rare to set it from the itemrenderer, usually 
> some other code accesses datagrid.column[i].width.
> 
> 
> On 5/19/10 11:02 AM, "method_air"  wrote:
> 
> 
> 
> 
> 
> 
> How do you vary the data grid column widths? Setting the width property 
> inside the item renderers to different values is not working.
> 
> Thanks,
> 
> Philip
> 
> 
> 
> 
> 
> 
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>




Re: [flexcoders] Re: Data grid vary column sizes

2010-05-21 Thread Alex Harui
Calculating column widths is not a built-in feature of the framework because it 
invites people to run code that has to visit every row in the dataprovider.

You can write such code yourself to compute the width of a column if you wish.


On 5/21/10 10:39 AM, "method_air"  wrote:






Autosizing a datagrids column width to fit the contents of a field is a common 
feature in other frameworks. Is there a Flex equivalent?

--- In flexcoders@yahoogroups.com  , 
Brendan Meutzner  wrote:
>
> The concept of auto fitting wouldn't really work for the simple reason that
> the row children are recycled as the content is scrolled.  If you did end up
> figuring out the functionality to make this happen from the itemRenderers,
> the column width would be constantly changing to "fit" to the currently
> viewable set of renderers.
>
>
> Brendan
>
>
>
> On Fri, May 21, 2010 at 11:52 AM, method_air  wrote:
>
> >
> >
> > Thanks. Is there a way for the column to intelligently 'autofit' to the
> > width of its contents?
> >
> >
> > --- In flexcoders@yahoogroups.com   
> > , "David"
> >  wrote:
> > >
> > > Set the width on the DataGridColumn, not on its itemRenderer
> > >
> > > --- In flexcoders@yahoogroups.com   
> > > ,
> > "method_air"  wrote:
> > > >
> > > > How do you vary the data grid column widths? Setting the width property
> > inside the item renderers to different values is not working.
> > > >
> > > > Thanks,
> > > >
> > > > Philip
> > > >
> > >
> >
> >
> >
>
>
>
> --
> Brendan Meutzner
> http://www.meutzner.com/blog/
> http://www.riajobs.com
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Data grid vary column sizes

2010-05-21 Thread method_air
Autosizing a datagrids column width to fit the contents of a field is a common 
feature in other frameworks. Is there a Flex equivalent?

--- In flexcoders@yahoogroups.com, Brendan Meutzner  wrote:
>
> The concept of auto fitting wouldn't really work for the simple reason that
> the row children are recycled as the content is scrolled.  If you did end up
> figuring out the functionality to make this happen from the itemRenderers,
> the column width would be constantly changing to "fit" to the currently
> viewable set of renderers.
> 
> 
> Brendan
> 
> 
> 
> On Fri, May 21, 2010 at 11:52 AM, method_air  wrote:
> 
> >
> >
> > Thanks. Is there a way for the column to intelligently 'autofit' to the
> > width of its contents?
> >
> >
> > --- In flexcoders@yahoogroups.com , "David"
> >  wrote:
> > >
> > > Set the width on the DataGridColumn, not on its itemRenderer
> > >
> > > --- In flexcoders@yahoogroups.com ,
> > "method_air"  wrote:
> > > >
> > > > How do you vary the data grid column widths? Setting the width property
> > inside the item renderers to different values is not working.
> > > >
> > > > Thanks,
> > > >
> > > > Philip
> > > >
> > >
> >
> >  
> >
> 
> 
> 
> -- 
> Brendan Meutzner
> http://www.meutzner.com/blog/
> http://www.riajobs.com
>




Re: [flexcoders] Re: Data grid vary column sizes

2010-05-21 Thread Brendan Meutzner
The concept of auto fitting wouldn't really work for the simple reason that
the row children are recycled as the content is scrolled.  If you did end up
figuring out the functionality to make this happen from the itemRenderers,
the column width would be constantly changing to "fit" to the currently
viewable set of renderers.


Brendan



On Fri, May 21, 2010 at 11:52 AM, method_air  wrote:

>
>
> Thanks. Is there a way for the column to intelligently 'autofit' to the
> width of its contents?
>
>
> --- In flexcoders@yahoogroups.com , "David"
>  wrote:
> >
> > Set the width on the DataGridColumn, not on its itemRenderer
> >
> > --- In flexcoders@yahoogroups.com ,
> "method_air"  wrote:
> > >
> > > How do you vary the data grid column widths? Setting the width property
> inside the item renderers to different values is not working.
> > >
> > > Thanks,
> > >
> > > Philip
> > >
> >
>
>  
>



-- 
Brendan Meutzner
http://www.meutzner.com/blog/
http://www.riajobs.com


[flexcoders] Re: Data grid vary column sizes

2010-05-21 Thread method_air
Thanks. Is there a way for the column to intelligently 'autofit' to the width 
of its contents?

--- In flexcoders@yahoogroups.com, "David"  wrote:
>
> Set the width on the DataGridColumn, not on its itemRenderer
> 
> --- In flexcoders@yahoogroups.com, "method_air"  wrote:
> >
> > How do you vary the data grid column widths? Setting the width property 
> > inside the item renderers to different values is not working.
> > 
> > Thanks,
> > 
> > Philip
> >
>




[flexcoders] Re: Data grid vary column sizes

2010-05-21 Thread David
Set the width on the DataGridColumn, not on its itemRenderer

--- In flexcoders@yahoogroups.com, "method_air"  wrote:
>
> How do you vary the data grid column widths? Setting the width property 
> inside the item renderers to different values is not working.
> 
> Thanks,
> 
> Philip
>