Фильтрация сетки данных на основе данных в строках, Flex - PullRequest
1 голос
/ 24 марта 2012

Сегодня я искал все, пытаясь найти, как это сделать, и незнаком с ActionScript начинает настигать меня. Я хотел бы сделать следующее: у меня есть список сообщений в Datagrid, поступающих от провайдера данных другого класса, который, в свою очередь, получает их из нашей БД Oracle. Мне нужно, чтобы все пользователи установили видимое состояние в сообщении, а затем отфильтровали его из сетки данных одним нажатием кнопки. У меня есть флажок для скрытия, и он устанавливает это значение в базу данных. Я не могу понять, как заставить filterFunction работать с коллекцией массивов, когда параметр фильтра находится внутри данных строки.

Вот код

public function filterResults():void {

            modelLocator.notification.messageList.filterFunction = filterRows;

            modelLocator.notification.messageList.refresh(); 


        }

        public function filterRows(item:Object):Boolean {
            //return true if row should stay visible
            //return false if it should go away

             var i:int;

            if(showAll == false) {//checks whether this is coming from the hide or show all button
            //Somehow need to interrogate the row data to check if messageVisible is set to true or false

             /* if (showAll == false) {
                return false;
            }else {
                return true;
            }
            return false; */ 

        }
        public var showAll:Boolean;

        public function showAllMessages():void{

            showAll = true;
            filterResults();
        }
        public function hideMessages():void{
            showAll = false;
            filterResults();
        }


    ]]>
</mx:Script>

<mx:VBox>
    <component:EditMessage id="editMessage"  width="930" height="445"/>
    <mx:Panel id="messageListPanel" title="Message History" layout="vertical" width="930" height="196" horizontalAlign="left">

        <mx:DataGrid id="messageDataGrid" dataProvider="{modelLocator.notification.messageList}" 
                     width="910" height="139" enabled="true" mouseEnabled="true" editable="false"
                     rowCount="5" itemClick="{selectMessage()}">

            <mx:columns>
                <mx:DataGridColumn headerText="Date Created" labelFunction="formatCreateDate" width="60"/>
                <mx:DataGridColumn headerText="From" dataField="senderEmail" width="100"/>
                <mx:DataGridColumn headerText="Subject" dataField="subject" width="100"/>
                <mx:DataGridColumn headerText="Start Date" labelFunction="formatStartDate" width="60"/>
                <mx:DataGridColumn headerText="End Date" labelFunction="formatEndDate" width="60" />
                <mx:DataGridColumn headerText="Date Sent" labelFunction="formatSendDate" width="60" />
                <mx:DataGridColumn headerText="Sender Netid" dataField="senderNetId" width="50" />
                <mx:DataGridColumn headerText="Sender Name" dataField="senderName" width="80" />
                <mx:DataGridColumn headerText="Message" dataField="message" width="100" />
                <mx:DataGridColumn headerText="Message Id" dataField="id" width="10" />
            </mx:columns>
        </mx:DataGrid>              
    </mx:Panel>                 
</mx:VBox>
<mx:Button id="showMessagesBtn" x="786" y="452" label="Show All Messages" click="showAllMessages()"/>
<mx:Button id="hideMessagesBtn" x="665" y="452" label="Hide Messages" click="hideMessages()" />

Я нашел здесь руководство по выполнению этого с входящим текстом http://franto.com/filter-results-in-datagrid-flex-tutorial/,, но не могу понять вышеупомянутую проблему, это действительно не может быть так сложно, не так ли?

Спасибо

Ian

1 Ответ

2 голосов
/ 24 марта 2012

элемент - это элемент поставщика данных, метод вызывается для каждого элемента в поставщике данных и помечает элемент для включения в длину и итерацию.

       public function filterResults():void {

            modelLocator.notification.messageList.filterFunction = filterRows;

            modelLocator.notification.messageList.refresh(); 


        }

        public function filterRows(item:Object):Boolean {
            if(showAll)
                return true;
            if(item.messageVisible=="true")
                return true;
            return false;
        }
        public var showAll:Boolean;

        public function showAllMessages():void{

            showAll = true;
            filterResults();
        }
        public function hideMessages():void{
            showAll = false;
            filterResults();
        }


    ]]>
</mx:Script>

<mx:VBox>
    <component:EditMessage id="editMessage"  width="930" height="445"/>
    <mx:Panel id="messageListPanel" title="Message History" layout="vertical" width="930" height="196" horizontalAlign="left">

        <mx:DataGrid id="messageDataGrid" dataProvider="{modelLocator.notification.messageList}" 
                     width="910" height="139" enabled="true" mouseEnabled="true" editable="false"
                     rowCount="5" itemClick="{selectMessage()}">

            <mx:columns>
                <mx:DataGridColumn headerText="Date Created" labelFunction="formatCreateDate" width="60"/>
                <mx:DataGridColumn headerText="From" dataField="senderEmail" width="100"/>
                <mx:DataGridColumn headerText="Subject" dataField="subject" width="100"/>
                <mx:DataGridColumn headerText="Start Date" labelFunction="formatStartDate" width="60"/>
                <mx:DataGridColumn headerText="End Date" labelFunction="formatEndDate" width="60" />
                <mx:DataGridColumn headerText="Date Sent" labelFunction="formatSendDate" width="60" />
                <mx:DataGridColumn headerText="Sender Netid" dataField="senderNetId" width="50" />
                <mx:DataGridColumn headerText="Sender Name" dataField="senderName" width="80" />
                <mx:DataGridColumn headerText="Message" dataField="message" width="100" />
                <mx:DataGridColumn headerText="Message Id" dataField="id" width="10" />
            </mx:columns>
        </mx:DataGrid>              
    </mx:Panel>                 
</mx:VBox>
<mx:Button id="showMessagesBtn" x="786" y="452" label="Show All Messages" click="showAllMessages()"/>
<mx:Button id="hideMessagesBtn" x="665" y="452" label="Hide Messages" click="hideMessages()" />
...