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

  • Home
  • SEARCH
  • 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 6391867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:44:28+00:00 2026-05-25T03:44:28+00:00

Is there a way in spark datagrid to disable some rows programmatically, in flex

  • 0

Is there a way in spark datagrid to disable some rows programmatically, in flex 3, it could be done using the function mouseEventToItemRenderer this way:

override protected function mouseEventToItemRenderer (
            event: MouseEvent): IListItemRenderer {
    var listItem: IListItemRenderer;// = super.mouseEventToItemRenderer(event);
    if (_disableFlag) 
    {
        if (listItem) 
        {
            if (listItem.data) 
            {
                if (disabledRow(listItem.data)) 
                {
                    return null;
                }
            }
        }
    }
    return listItem;
}

And then I implement the function disabledRow to return true or false depending on some condition, the condition that will specify if the selected item will be renderered or not. Is there a way in spark datagrid to do the same?

  • 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-25T03:44:29+00:00Added an answer on May 25, 2026 at 3:44 am

    Ok, so here’s how I did

    First Step

    I created the classes SelectionIndicator, HoverIndicator and CaretIndicator like the ones we find as skin parts in the datagrid skin, so the skin part caretIndicator:

    <!--- @private -->        
    <fx:Component id="caretIndicator">
        <s:Rect implements="spark.components.gridClasses.IGridVisualElement">
            <fx:Script>
                <![CDATA[
                    import spark.components.DataGrid;
                    import spark.components.Grid;
    
                    /**
                     * @private
                     */
                    public function prepareGridVisualElement(grid:Grid, rowIndex:int, columnIndex:int):void
                    {
                        const dataGrid:DataGrid = grid.dataGrid;
                        if (!dataGrid)
                            return;
    
                        const color:uint = dataGrid.getStyle("caretColor");
                        caretIndicatorFill.color = color;
                    }
                ]]>
            </fx:Script>
    
            <s:stroke>
                <!--- @private -->
                <s:SolidColorStroke id="caretIndicatorFill" color="0x0167FF" weight="1"/>
            </s:stroke>
       </s:Rect>
    </fx:Component>
    

    becomes

    package com.tn.zuro.components
    {
        import mx.graphics.SolidColorStroke;
    
        import spark.components.DataGrid;
        import spark.components.Grid;
        import spark.components.gridClasses.IGridVisualElement;
        import spark.primitives.Rect;
    
        public class CaretIndicator extends Rect implements IGridVisualElement
        {
            private var caretIndicatorFill:SolidColorStroke ;
    
            public function CaretIndicator()
            {
                super();
                caretIndicatorFill = new SolidColorStroke();
                this.stroke = caretIndicatorFill;
            }
    
            public function prepareGridVisualElement(grid:Grid, rowIndex:int, columnIndex:int):void
            {
                const dataGrid:DataGrid = grid.dataGrid;
                if (!dataGrid)
                    return;
    
                const color:uint = dataGrid.getStyle("caretColor");
                caretIndicatorFill.color = color;
            }
        }    
    }
    

    The same goes for SelectionIndicator and HoverIndicator, just don’t forget to use SolidColor instead of solidColorStroke and the property fill or Rect instead of the property stroke.

    Second Step

    In the personalized datagrid, I added event listeners for the events gridClick, gridRollOver and gridMouseDown:

    this.addEventListener(GridEvent.GRID_CLICK, gridClickHandler);
    this.addEventListener(GridEvent.GRID_ROLL_OVER, gridEventHandler);
    this.addEventListener(GridEvent.GRID_MOUSE_DOWN, mouse_down_handler);
    

    And here are the event listeners:

    protected function mouse_down_handler(event:GridEvent):void
    {
        if (_disableFlag)
        {
            if (event.item)
            {
                if (disabledRow(event.item))
                {
                    event.grid.caretIndicator = null;
                    event.grid.selectionIndicator = null;
                }
            }
        }
    }
    
    protected function gridClickHandler(event:GridEvent):void
    {
        if (_disableFlag)
        {
            if (event.item)
            {
                if (!disabledRow(event.item))
                {
                    event.grid.selectionIndicator = new ClassFactory(SelectionIndicator);
                    event.grid.caretIndicator = new ClassFactory(CaretIndicator);
                }
            }
        }
    }
    
    protected function gridEventHandler(event:GridEvent):void
    {
        if (_disableFlag)
        {
            if (event.item)
            {
                if(disabledRow(event.item))
                {   
                    event.grid.hoverIndicator = null;
                }
                else
                {
                    event.grid.hoverIndicator = new ClassFactory(HoverIndicator);
                }
            }
        }
    }
    

    You probably already guessed that _disableFlag and disabledRow are respectively a Boolean and a Function. Now the last step is the easiest:

    Third Step

    When you use the personalized dataGrid, if you want to disable the columns, you set _disableFlag to true and implement the disabledRow which returns true if a condition is met, and false if not

    <custom:NinjaGrid id="ninja"
                     _disableFlag=true
                      creationComplete="ninja_trainingCompleteHandler(event)"/>
    

    protected function ninja_trainingCompleteHandler(event:FlexEvent):void
    {
        ninja.disabledRow = beNinja;
    }
    private function beNinja(ninja:Object):Boolean
    {
        if (ninja.knowHowToWalkOnWater == true)
            return true;
        return false;
    }
    

    This solution doesn’t work for the selection mode multiple rows, I found another solution for the multiple rows selection mode.


    Second Solution

    In this solution, I use only the HoverIndicator component, the event listener for the rollover event will remain the same. I don’t use the event listener for the click event anymore, and in the mouse_down_handler function, I have now this code:

    protected function mouse_down_handler(event:GridEvent):void
    {
        if(_disableFlag)
        {
            if (event.item)
            {
                if (!disabledRow(event.item))
                {
                    if (!event.ctrlKey)
                    {
                        tempItem = event.item;
                        tempSelecteditems = new Vector.<Object>();
                        tempSelecteditems.push(tempItem);
                    }
                    else
                    {
                        if (tempSelecteditems.indexOf(event.item) < 0)
                        {
                            tempSelecteditems.push(event.item);
                        }
                        else
                        {
                            tempSelecteditems[tempSelecteditems.indexOf(event.item)] = null;
                        }
                    }
    
                } 
                else
                {
                    if (!event.ctrlKey)
                    {
                        selectedItem = tempItem;
                        tempSelecteditems = new Vector.<Object>();
                    } 
                    else
                    {
                        if (tempSelecteditems.length)
                        {
                            selectedItems = tempSelecteditems;
                        }
                        else
                        {
                            selectedItem = tempItem;
                        }
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to disable (and look disabled) some rows in a spark datagrid. I
Is there any way to check whether a file is locked without using a
Is there a way to hide radio buttons inside a RadioButtonList control programmatically?
Is there a way to prevent recycling of item rendered with Spark components on
Is there a way to email an ASP.NET View using the standard view engine
Is there a way to change the space between a spark form item and
I am using Flex 4 with Spark components to build a mobile application and
Is there a simple way to do this? (Change the colour of the headings
Is there any way to change Spark button label dynamically? When i click on
Is there a simple way to animate the color of an object using actionscript

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.