Hi,
You need to extend the existing datagrid class and override the
existing getSeparator function
as follows:
If anyone knows the optimized solution please post it.
override protected function getSeparator(i:int,
seperators:Array,
headerLines:UIComponent):UIComponent
{
var sep:UIComponent = super.getSeparator(i, seperators,
headerLines);
sep.doubleClickEnabled = true;
// Add listener for Double Click
DisplayObject(sep).addEventListener(MouseEvent.DOUBLE_CLICK,
columnResizeDoubleClickHandler);
return sep;
}
/**
* @private
* Indicates where the right side of a resized column appears.
*/
protected function
columnResizeDoubleClickHandler(event:MouseEvent):void
{
// check if the ADG is enabled and the columns are resizable
if (!enabled || !resizableColumns)
return;
var target:DisplayObject = DisplayObject(event.target);
var index:int = target.parent.getChildIndex(target);
// get the columns array
var optimumColumns:Array = getOptimumColumns();
var col:AdvancedDataGridColumn = optimumColumns[index];
// check for resizable column
if (!col.resizable)
return;
var lineMetrics:TextLineMetrics = measureText(col.headerText);
var expectedColWidth:Number = lineMetrics.width + 20 ; // 20
(added
approximately to set initial width of the column).
// calculate the maxWidth - we can optimize this calculation
if(listItems)
{
var len:int = listItems.length;
var maxWidth:int = 0;
for(var i:int=0;i<len;i++)
{
if(listItems[i][index] is IDropInListItemRenderer)
{
lineMetrics =
measureText(IDropInListItemRenderer(listItems[i]
[index]).listData.label);
if(lineMetrics.width > maxWidth)
maxWidth = lineMetrics.width ;
}
}
}
if(expectedColWidth > maxWidth)
maxWidth =expectedColWidth;
col.width = maxWidth + getStyle("paddingLeft") +
getStyle("paddingRight") + 8;
}
Regards,
Raj
On Jul 2, 3:16 pm, oviya selvan <[email protected]> wrote:
> Hi
>
> First of all thank you so much for your quick responses. Yes i don't
> wanna wrap the text into multiple rows, but adjust the width of column and
> put data in single line.
>
> One more thing i wanna add here. I am dealing with 66 columns and
> minimum of 1500 rows. The number of rows may go up to 6000. So please
> give me an optimal solution.
>
> Actually i am thinking about alternative way, since this may be tough to
> achieve with good performance.
>
> *Alternate:*
> In MS-Excel, we have option to click the column separator. when we click on
> column separator, the appropriate column width will get adjust.
>
> Since adjust/alter width of all columns in one shot will bring down the
> performance. we can think about this option here we are perform action for
> only one column at a time. But i don't know how to capture events of
> separator.
>
> Please throw your ideas folks!!!.
>
> Thanks once again guys.
>
> With Regards,
> Oviyan
>
>
>
> On Fri, Jul 2, 2010 at 10:33 AM, raj <[email protected]> wrote:
> > Hi,
>
> > You need to calculate each cell width and assign the column width as
> > maximum of these as follows.
>
> > {
> > // check if the ADG is enabled and the columns are resizable
> > if (!enabled || !resizableColumns)
> > return;
>
> > // get the columns array
> > var optimumColumns:Array = getOptimumColumns();
> > var colLen:int = optimumColumns.length;
> > var col:AdvancedDataGrid;
> > for (var index:int =0; index < colLen; index++)
> > {
> > col = optimumColumns[index];
> > // check for resizable column
> > if (!col.resizable)
> > return;
>
> > if(listItems)
> > {
> > var len:int = listItems.length;
> > var maxWidth:int = 0;
> > for(var i:int=0;i<len;i++)
> > {
> > if(listItems[i][index] is IDropInListItemRenderer)
> > {
> > lineMetrics =
> > measureText(IDropInListItemRenderer(listItems[i]
> > [index]).listData.label);
> > if(lineMetrics.width > maxWidth)
> > maxWidth = lineMetrics.width ;
> > }
> > }
> > }
>
> > col.width = maxWidth + getStyle("paddingLeft") +
> > getStyle("paddingRight");
> > }
>
> > }
>
> > If you have larget sets of data, then this method will take more
> > time.
>
> > If anyone have better idea than this, please share.
>
> > Regards,
> > Raj
>
> > On Jul 1, 5:08 pm, oviya selvan <[email protected]> wrote:
> > > Hi Guys,
>
> > > I am held up on an issue related to width adjustment of
> > datagridColumn
> > > dynamically. Let me put it like this, I have a datagrid and data has been
> > > populated dynamically. I wanna define the width of column of DataGrid
> > based
> > > on length of data(dynamic). I think that we can use itemrenderer but i am
> > > more concern about performance. So please shed some lights on this
> > folks!!.
>
> > > Thanks in advance.
>
> > > --
> > > Regards,
> > > Oviyan
>
> > > Blog : http://www.oviyas.blogspot.com/
> > > contact : +91 - 91762 72633
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Flex India Community" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<flex_india%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/flex_india?hl=en.
>
> --
> Regards,
> Oviyan
>
> Blog : http://www.oviyas.blogspot.com/
> contact : +91 - 91762 72633
--
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en.