Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5843531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:10:02+00:00 2026-05-22T12:10:02+00:00

Tried col.setStyle(‘percentWidth’,20) //doesn’t work col.setStyle(‘percentWidth’,0.2)//doesn’t work && col.percentWidth //doesnt compile where col is one

  • 0

Tried

col.setStyle('percentWidth',20) //doesn't work

col.setStyle('percentWidth',0.2)//doesn't work

&&

col.percentWidth //doesnt compile

where col is one of the columns in a datagrid

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:10:03+00:00Added an answer on May 22, 2026 at 12:10 pm

    Use the following extended datagrid:

    package {
    import mx.controls.DataGrid;
    import mx.events.DataGridEvent;
    
    public class ExDataGrid extends DataGrid {
    
        //--------------------------------------
        //   Constructor 
        //--------------------------------------
    
        public function ExDataGrid() {
            super();
            addEventListener(DataGridEvent.COLUMN_STRETCH, onColumnStretch);
        }
    
        //------------------------------------------------------------------------------
        //   Properties 
        //------------------------------------------------------------------------------
    
        //--------------------------------------
        //   Private 
        //--------------------------------------
    
        /**
         * @private
         * Keeps track of whether the columns have been manually adjusted or not. If they
         * have, then do not apply the columnWidths that have been specified.
         */
        private var _columnsAdjusted : Boolean = false;
    
        /**
         * @private
         * Storage for the columnWidths property.
         */
        private var _columnWidths : Array = new Array();
    
        /**
         * @private
         */
        private var _columnWidthsChanged : Boolean = false;
    
        /**
         * @private
         * Stores the explicit width portions of the column widths.
         */
        private var _explicitColWidths : Object;
    
        /**
         * @private
         * Stores the percentage width portions of the column widths.
         */
        private var _percentColWidths : Object;
    
        //--------------------------------------
        //   Getters / Setters 
        //--------------------------------------
    
        public function get columnWidths() : Array {
            return _columnWidths;
        }
    
        /**
         * Sets the widths of each of the columns. The widths can either be percentages or
         * explicit widths. For each column in the DataGrid, there should be a column width
         * value. The column widths should be expressed as strings.
         *
         * If there are 4 columns and we want the 1st column to be 40% width, the 2nd column
         * to be 60% width, the 3rd column to be a fixed width of 200, and the 4th column to
         * be a fixed width of 300. Then we would set the columnWidths property to be:
         * ['40%', '60%', 200, 300]
         */
        public function set columnWidths(values : Array) : void {
            if (_columnWidths != values) {
                _columnWidths = values;
                _columnWidthsChanged = true;
    
                invalidateProperties();
                invalidateDisplayList();
            }
        }
    
        //------------------------------------------------------------------------------
        //   Functions  
        //------------------------------------------------------------------------------
    
        //--------------------------------------
        //   Protected 
        //--------------------------------------
    
        /**
         * @private
         */
        override protected function commitProperties() : void {
            super.commitProperties();
    
            if (_columnWidthsChanged) {
                splitPercentWidths(columnWidths);
                _columnWidthsChanged = false;
            }
        }
    
        /**
         * @private
         * Sizes each of the columns in the DataGrid based on the columnWidths property,
         * unless the user has manually resized the columns, then the column widths will
         * not be adjusted.
         */
        override protected function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void {
            // Determine how much width is left over for percentage calculations after the fixed
            // widths are allocated.
            var leftoverWidth : Number = unscaledWidth;
    
            for each (var explicitColWidth : Number in _explicitColWidths) {
                leftoverWidth -= explicitColWidth;
            }
    
            // Manually adjust the column width before doing super.updateDisplayList. This way when 
            // super.updateDisplayList is called, it can perform any minor adjustments to the columns, 
            // but the column widths will still be pretty consistant with the specified widths.
            if (columns && columnWidths && !_columnsAdjusted && columns.length == columnWidths.length) {
                for (var i : int = 0; i < columnWidths.length; i++) {
                    var w : Number = 0;
    
                    if (_explicitColWidths[i]) {
                        w = _explicitColWidths[i];
                    }
                    else {
                        w = leftoverWidth * (_percentColWidths[i] / 100);
                    }
    
                    // Adjust the column's width. After digging through the DataGridColumn, I found 
                    // 3 different properties that need to be set to override the default column width 
                    // calculations performed by DataGrid and DataGridColumn. They are _width (changed 
                    // in the setWidth method), explicitWidth, and preferredWidth.
                    columns[i].setWidth(w);
                    columns[i].explicitWidth = w;
                    columns[i].preferredWidth = w;
                }
            }
    
            super.updateDisplayList(unscaledWidth, unscaledHeight);
        }
    
        //--------------------------------------
        //   Private 
        //--------------------------------------
    
        /**
         * @private
         */
        private function onColumnStretch(event : DataGridEvent) : void {
            _columnsAdjusted = true;
        }
    
        /**
         * Called from the <code>commitProperties()</code> method to break up the columnWidths
         * into percentage based widths and explicit widths.
         *
         * When we calculate the percentage widths in <code>updateDisplayList()</code> we need
         * to know the remaining available width after explicit widths are subtracted.
         */
        private function splitPercentWidths(values : Array) : void {
            if (columns && columnWidths && columnWidths.length > 0) {
                _percentColWidths = new Object();
                _explicitColWidths = new Object();
    
                for (var i : uint = 0; i < columnWidths.length; i++) {
                    var columnWidth : String = columnWidths[i] + "";
    
                    // If columnWidth contains a '%' then it is a percentage width, otherwise
                    // it is an explicit width.
                    if (columnWidth.indexOf("%") == -1) {
                        _explicitColWidths[i] = Number(columnWidth);
                    }
                    else {
                        _percentColWidths[i] = Number(columnWidth.substr(0, columnWidth.length - 1));
                    }
                }
            }
        }
    }
    }
    

    Declare all column widths as at array assigned to ‘columnWidths’ with the following syntax:

     columnWidths = ['70%','30%','100'];
    

    Widths without a % sign are treated normally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Tried a bunch of things but I can't get it to work consistently amid
There are 5 columns in my table view. Col-1 - Non editable Col-2 -
I tried to figure out a dynamic query to get date col within past
I have tried to make method which changes one color of BufferedImage to be
I want to find only those rows whose column 'col' c doesn't contain characters
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
Tried following the instructions here: How to use Google app engine with my own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.