DataGrid 中的删除线

发布于 2024-11-29 02:53:02 字数 38 浏览 4 评论 0原文

给定一些规则,我想删除 DataGrid 中的整行。是否可以?

Given some rule I want to strike through an entire row in a DataGrid. Is it possible?

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

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

发布评论

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

评论(2

誰ツ都不明白 2024-12-06 02:53:02

实现这项工作的最可靠的方法是使用自定义项目渲染器,其中重写 OnUpdateDisplay 函数,您使用图形对象基于布尔值在数据网格项目的标签之间绘制一条水平线范围。

如果您愿意,我可以为标签写下类似的内容,但您必须弄清楚使其与 Datagrid 项目组件一起工作的内部原理。

如果您希望我粘贴标签示例,请告诉我。

编辑(粘贴示例)

创建一个新的flex项目,添加一个扩展标签的新类。该类的名称是StrikeThroughLabel。现在将其放入默认包中(即将包字段留空)

    package
{
    import mx.controls.Label;

    public class StrikeThroughLabel extends Label
    {
        private var isStriked:Boolean = false;

        public function StrikeThroughLabel()
        {
            super();
        }

        public function set striked(aIsStriked:Boolean):void{
            isStriked =  aIsStriked;
            this.updateDisplayList(this.width, this.height);
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if(isStriked){
                graphics.lineStyle(1,0x0000FF,1,false,"normal",null,null,3.0);
                graphics.lineTo(unscaledWidth,unscaledHeight);
            }else{
                graphics.clear();
            }
        }
    }
}

完成后,进入 main.mxml 并使用 mxml 后面的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="windowedapplication1_creationCompleteHandler(event)"
                        xmlns:local="*">
    <local:StrikeThroughLabel id="strikeThrough" text="Hello" x="129" y="128"/>
    <mx:Script>
        <![CDATA[
            import mx.events.FlexEvent;


            private var isLabelStriked:Boolean = false;

            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                //this.strikeThrough.striked = true;    
            }


            protected function button1_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                isLabelStriked = !isLabelStriked;
                this.strikeThrough.striked = isLabelStriked;
            }

        ]]>
    </mx:Script>
    <mx:Button click="button1_clickHandler(event)" id="myButton" label="Toggle"/>
</mx:WindowedApplication>

上面显示了一个按钮和一个标签,单击按钮会切换标签上的删除线。
请注意,现在删除线是对角线的,但只需在登录绘制线时进行一些调整,您就应该得到水平删除线。

The most robust way to make this work , would be to use a custom item-renderer, where overriding the OnUpdateDisplay function, you use a graphic object to draw a horizontal line right between the label of the data-grid item, based on a boolean parameter.

I can write down something like this for a label if you want, but you will have to figure out the internals of making it work with the Datagrid item component.

Please let me know if you want me to paste an example for label.

EDIT (PASTING EXAMPLE)

Create a new flex project, add a new class which extends label.The name of the class is StrikeThroughLabel .Put this in the default package as of now (i.e leave the package field empty)

    package
{
    import mx.controls.Label;

    public class StrikeThroughLabel extends Label
    {
        private var isStriked:Boolean = false;

        public function StrikeThroughLabel()
        {
            super();
        }

        public function set striked(aIsStriked:Boolean):void{
            isStriked =  aIsStriked;
            this.updateDisplayList(this.width, this.height);
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if(isStriked){
                graphics.lineStyle(1,0x0000FF,1,false,"normal",null,null,3.0);
                graphics.lineTo(unscaledWidth,unscaledHeight);
            }else{
                graphics.clear();
            }
        }
    }
}

Once thats done, come to your main.mxml and use the code that follows for mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="windowedapplication1_creationCompleteHandler(event)"
                        xmlns:local="*">
    <local:StrikeThroughLabel id="strikeThrough" text="Hello" x="129" y="128"/>
    <mx:Script>
        <![CDATA[
            import mx.events.FlexEvent;


            private var isLabelStriked:Boolean = false;

            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                //this.strikeThrough.striked = true;    
            }


            protected function button1_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                isLabelStriked = !isLabelStriked;
                this.strikeThrough.striked = isLabelStriked;
            }

        ]]>
    </mx:Script>
    <mx:Button click="button1_clickHandler(event)" id="myButton" label="Toggle"/>
</mx:WindowedApplication>

The above shows you a button and a label, clicking on the button toggles the strikethrough on the label.
Please note, right now the strike-through is diagonal, but just a few tweaks with the login of drawing the line, and you should get a horizontal strike-throught.

单调的奢华 2024-12-06 02:53:02

我不确定这是否有帮助,但我只想到这个。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
    <![CDATA[

        import mx.collections.ArrayCollection;

        [Bindable]
        private var stepsObjs:ArrayCollection = new ArrayCollection();
        private function init():void
        {
            stepsObjs.addItem(new CObj(100,100,true));
            stepsObjs.addItem(new CObj(700,800,false));
        }

    ]]>
</mx:Script>

<mx:DataGrid id="dg" dataProvider="{stepsObjs}" click="{dg.selectedItem.strike = !dg.selectedItem.strike}" editable="false">
    <mx:columns>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Canvas width="100%" 
                        height="100%" 
                        horizontalScrollPolicy="off" 
                        verticalScrollPolicy="off">
                        <mx:Script>
                            <![CDATA[
                                override public function set data( value:Object ) : void {
                                    super.data = value;
                                }
                            ]]>
                        </mx:Script>
                        <mx:TextArea text="{data.x}" borderStyle="none" editable="false"/>
                        <mx:HRule strokeColor="red" width="100%" visible="{data.strike}" y="{this.height/2}"/>
                    </mx:Canvas>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Canvas width="100%" 
                        height="100%" 
                        horizontalScrollPolicy="off" 
                        verticalScrollPolicy="off">
                        <mx:Script>
                            <![CDATA[
                                override public function set data( value:Object ) : void {
                                    super.data = value;
                                }
                            ]]>
                        </mx:Script>
                        <mx:TextArea text="{data.y}" borderStyle="none" editable="false"/>
                        <mx:HRule strokeColor="red" width="100%" visible="{data.strike}" y="{this.height/2}"/>
                    </mx:Canvas>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>

    </mx:columns>
</mx:DataGrid>  
</mx:Application>

CObj 类

package
{
    [Bindable]  
    public class CObj
    {
        public function CObj(x:Number , y:Number , str:Boolean)
        {
            this.x = x;
            this.y = y;
            this.strike = str;

        }
        public var x:Number;
        public var y:Number;
        public var strike:Boolean;

    }
}

Am not sure if this help or it , but only this one comes to my mind.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
    <![CDATA[

        import mx.collections.ArrayCollection;

        [Bindable]
        private var stepsObjs:ArrayCollection = new ArrayCollection();
        private function init():void
        {
            stepsObjs.addItem(new CObj(100,100,true));
            stepsObjs.addItem(new CObj(700,800,false));
        }

    ]]>
</mx:Script>

<mx:DataGrid id="dg" dataProvider="{stepsObjs}" click="{dg.selectedItem.strike = !dg.selectedItem.strike}" editable="false">
    <mx:columns>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Canvas width="100%" 
                        height="100%" 
                        horizontalScrollPolicy="off" 
                        verticalScrollPolicy="off">
                        <mx:Script>
                            <![CDATA[
                                override public function set data( value:Object ) : void {
                                    super.data = value;
                                }
                            ]]>
                        </mx:Script>
                        <mx:TextArea text="{data.x}" borderStyle="none" editable="false"/>
                        <mx:HRule strokeColor="red" width="100%" visible="{data.strike}" y="{this.height/2}"/>
                    </mx:Canvas>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Canvas width="100%" 
                        height="100%" 
                        horizontalScrollPolicy="off" 
                        verticalScrollPolicy="off">
                        <mx:Script>
                            <![CDATA[
                                override public function set data( value:Object ) : void {
                                    super.data = value;
                                }
                            ]]>
                        </mx:Script>
                        <mx:TextArea text="{data.y}" borderStyle="none" editable="false"/>
                        <mx:HRule strokeColor="red" width="100%" visible="{data.strike}" y="{this.height/2}"/>
                    </mx:Canvas>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>

    </mx:columns>
</mx:DataGrid>  
</mx:Application>

CObj Class

package
{
    [Bindable]  
    public class CObj
    {
        public function CObj(x:Number , y:Number , str:Boolean)
        {
            this.x = x;
            this.y = y;
            this.strike = str;

        }
        public var x:Number;
        public var y:Number;
        public var strike:Boolean;

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