Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Flex (http://www.flasher.ru/forum/forumdisplay.php?f=84)
-   -   Получить доступ к строке GridView из внутреннего контрола (http://www.flasher.ru/forum/showthread.php?t=101791)

zurmansor 03.10.2007 12:16

Получить доступ к строке GridView из внутреннего контрола
 
У меня есть GridView
Код:

  <mx:DataGrid id="grid" editable="true" left="0" right="0" top="0" bottom="0" itemEditEnd="Edit(event)"
                dataTipField="ID">
        <mx:columns>
            <mx:DataGridColumn headerText="ID" dataField="ID" width="100" editable="false"/>
            <mx:DataGridColumn headerText="Name" dataField="Name" editable="true"/>
            <mx:DataGridColumn headerText="" editable="false" width="100">
            <mx:itemRenderer>
                    <mx:Component>
                            <mx:Button click="" label="delete"/>
                    </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>

как из кнопки "delete" достучаться до номера строки в которой находится эта кнопка? И вообще как грамотно реализовать добавление-удаление-редактирование данных в GridView? Или хотябы удаление, с остльным я вроде бы разобрался.

baron27 03.10.2007 13:02

из итемрендерера добраться до внешнего приложения можно через outerDocument или parentDocument. Управлять гридом нужно через его датапровайдер с помощью конструкций типа dg.selectedItem.fieldName.

Sneg 03.10.2007 18:38

Можно написать свой itemRenderer с кнопкой, который при нажатии на неё будет диспетчить свое сообщение, с необходимыми вам параметрами. В приложении ловить его и совершать необходимые действия.

NikR 03.10.2007 23:01

№ строки: grid.selectedIndex
Строка: delete.data

Sneg 03.10.2007 23:37

Из
Код:

                    <mx:Component>
                            <mx:Button click="" label="delete"/>
                    </mx:Component>

Переменная grid надоступна из Component, так что grid.selectedIndex не сработает.

lowka 04.10.2007 00:54

Код:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">       
        <mx:DataGrid width="500">
                <mx:dataProvider>
                        <mx:ArrayCollection>
                                <mx:Object artist="Fused" album="Audio" price="18.99" />
                                <mx:Object artist="Squarepusher" album="Hello Everything" price="16.98"/>
                                <mx:Object artist="Ellen Allien" album="Berlinette" price="16.98"/>
                                <mx:Object artist="Vargo" album="Beauty" price="16.98"/>
                                <mx:Object artist="Orbital" album="In Sides" price="11.98"/>
                                <mx:Object artist="Prefuse 73" album="One Word Extinguisher" price="16.98"/>
                        </mx:ArrayCollection>
                </mx:dataProvider>
                <mx:columns>
                        <mx:DataGridColumn dataField="artist" headerText="Artist" />
                        <mx:DataGridColumn dataField="album" headerText="Album" />
                        <mx:DataGridColumn dataField="price" headerText="Price" />
                        <mx:DataGridColumn headerText="" editable="false" width="100" itemRenderer="renderers.Renderer"/>
                </mx:columns>
        </mx:DataGrid>
</mx:Application>

renderers/Renderer.mxml:
Код:

<?xml version="1.0" ?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script>
                <![CDATA[
                        import flash.events.MouseEvent;
                        import mx.collections.ArrayCollection;
                        import mx.controls.dataGridClasses.DataGridBase;
                       
                        private function clickHandler(event:MouseEvent):void
                        {
                                var dataGrid:DataGridBase = DataGridBase(this.owner);
                                var arrayCollection:ArrayCollection = dataGrid.dataProvider as ArrayCollection;
                               
                                arrayCollection.removeItemAt(dataGrid.selectedIndex);
                        }
                ]]>
        </mx:Script>
       
        <mx:Button label="delete" click="clickHandler(event)" />
</mx:HBox>


zurmansor 04.10.2007 17:27

Цитата:

Сообщение от NikR
Строка: delete.data

Вот этого не понял, можно поподробнее, пожалуста?

Цитата:

Сообщение от Sneg
Переменная grid надоступна из Component, так что grid.selectedIndex не сработает.

Доступна, только через левую заднюю ногу:
Код:

mx.core.Application.application['grid']
to lowka: Уря! получилось. почти так и сделал:
Код:

<mx:Button click="mx.core.Application.application['Delete']();" label="delete"/>
и
Код:

public function Delete():void{
  var arrayCollection:ArrayCollection = grid.dataProvider as ArrayCollection;
  arrayCollection.removeItemAt(grid.selectedIndex);
}


baron27 04.10.2007 17:31

я же говорю:
parentDocument.grid
outerDocument.grid

zurmansor 04.10.2007 17:41

Цитата:

Сообщение от baron27
я же говорю:
parentDocument.grid
outerDocument.grid

Спасибо, переделал таким образом. Так действительно проще :)

baron27 04.10.2007 18:21

паблик методы тоже вызываются таким образом.
Методы называются с маленькой буквы, но каждое следующее слово идет с большой.


Часовой пояс GMT +4, время: 20:43.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.