Flex Spark datagrid - 禁用行选择

发布于 2024-12-05 12:04:08 字数 387 浏览 1 评论 0原文

我想禁用(并且看起来禁用)spark 数据网格中的某些行。我找到了这个答案来停止选择,这很棒 在flex中,有没有一种方法可以捕获并选择性地取消DataGrid中的行选择事件?

但我还想表明特定行是不可选择的。理想情况下,我想要某种覆盖,但我不确定这是否可能。我的替代解决方案是将不可选择的行的文本颜色更改为灰色。查看数据网格渲染,它们似乎都是基于列的。我研究了潜在的蒙皮(覆盖交替颜色属性),但这只是设置背景属性而不是文本颜色。这可能吗?

谢谢

I want to disable (and look disabled) some rows in a spark datagrid. I found this answer to stop selection which is great
In flex, is there a way to capture and optionally cancel a row selection event in a DataGrid?

But I want in addition to show that the particular row is not selectable. Ideally I want to have some sort of overlay but I am not sure if that is possible. My alternative solution is to change the text color to grey for the unselectable row. Looking at the datagrid renders they all seem to be column based. I looked at skinning potentially (overriding the alternating color property) but this just sets the background property and not the text color. Is this possible?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲喜皆因你 2024-12-12 12:04:08

最基本的解决方案是使用您提到的自定义渲染器和选择阻止逻辑:

DataGridRowDisabling.mxml

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:local="*">

    <fx:Script>
    <![CDATA[
        import spark.events.GridSelectionEvent;

        private function dataGrid_selectionChangingHandler(event:GridSelectionEvent):void
        {
            var index:int = event.selectionChange.rowIndex;
            var product:Product = dataGrid.dataProvider.getItemAt(index) as Product;
            if (product && !product.enabled)
                event.preventDefault();
        }

    ]]>
    </fx:Script>

    <s:DataGrid id="dataGrid" itemRenderer="GridItemRenderer2" selectionChanging="dataGrid_selectionChangingHandler(event)">
        <s:dataProvider>
            <s:ArrayCollection>
                <local:Product name="iPod" price="199.99"/>
                <local:Product name="iPad 3" price="499.99"/>
                <local:Product name="iPad 4" price="599.99" enabled="false"/>
                <local:Product name="iPad 5" price="699.99" enabled="false"/>
            </s:ArrayCollection>
        </s:dataProvider>
    </s:DataGrid>

</s:Application>

GridItemRenderer2.mxml

<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">

    <fx:Script>
    <![CDATA[

        override public function prepare(hasBeenRecycled:Boolean):void 
        {
            if (data is Product)
                enabled = Product(data).enabled;

            lblData.text = data[column.dataField];
        }

    ]]>
    </fx:Script>

    <s:Label id="lblData" top="9" left="7"/>

</s:GridItemRenderer>

Product.as

package
{
public class Product
{

    public var name:String;

    public var price:Number;

    public var enabled:Boolean = true;

}
}

The most basic solution is using the custom renderer and selection preventing logic you've mentioned:

DataGridRowDisabling.mxml

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:local="*">

    <fx:Script>
    <![CDATA[
        import spark.events.GridSelectionEvent;

        private function dataGrid_selectionChangingHandler(event:GridSelectionEvent):void
        {
            var index:int = event.selectionChange.rowIndex;
            var product:Product = dataGrid.dataProvider.getItemAt(index) as Product;
            if (product && !product.enabled)
                event.preventDefault();
        }

    ]]>
    </fx:Script>

    <s:DataGrid id="dataGrid" itemRenderer="GridItemRenderer2" selectionChanging="dataGrid_selectionChangingHandler(event)">
        <s:dataProvider>
            <s:ArrayCollection>
                <local:Product name="iPod" price="199.99"/>
                <local:Product name="iPad 3" price="499.99"/>
                <local:Product name="iPad 4" price="599.99" enabled="false"/>
                <local:Product name="iPad 5" price="699.99" enabled="false"/>
            </s:ArrayCollection>
        </s:dataProvider>
    </s:DataGrid>

</s:Application>

GridItemRenderer2.mxml

<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">

    <fx:Script>
    <![CDATA[

        override public function prepare(hasBeenRecycled:Boolean):void 
        {
            if (data is Product)
                enabled = Product(data).enabled;

            lblData.text = data[column.dataField];
        }

    ]]>
    </fx:Script>

    <s:Label id="lblData" top="9" left="7"/>

</s:GridItemRenderer>

Product.as

package
{
public class Product
{

    public var name:String;

    public var price:Number;

    public var enabled:Boolean = true;

}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文