带有条件链接的 Flex Datagrid

发布于 2024-12-05 16:35:48 字数 165 浏览 0 评论 0原文

我需要你的帮助来关注。

我有一个数据网格,它使用数组列表作为数据提供者。现在我的要求是在该数组列表中,我有一个 statusId 作为一个变量,或者说我显示为数据网格中的列之一的属性。现在我有另一列,我必须在其中显示三个链接,例如编辑、删除和查看,这将基于 statusid。你能给我一些想法或例子吗

I need your help on following.

I have one datagrid which use an arraylist as a data provider. Now my requirment is in that arraylist i have one statusId as one variable or say property which i display as one of the column in datagrid. now i have another column where i have to display three links like edit, delete and view which will be based on the statusid. can you give me some idea or example

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

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

发布评论

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

评论(2

蘑菇王子 2024-12-12 16:35:48

我不是 Flex 专家,但通常当您想要自定义 DataGrid 中列的外观时,您会使用 ItemRenderer,如标记所示。在项目渲染器中,您可以使用 Label 组件并设置一系列属性,使它们看起来像链接,然后根据您的情况启用/禁用它们。

下面是我突然想到的一些示例代码,但有以下注意事项:

  • 我使用的是 MX DataGrid,而不是 Spark DataGrid。
  • 为了方便起见,我使用内联项目渲染器,但更好的做法是将项目渲染器外部化到单独的 MXML 文件中。

    
        
            
            
                ;
                    
                        
                        
                        
                    
                
            
        
    
    

I'm no Flex expert, but usually when you want to customise the appearance of a column in a DataGrid you use an ItemRenderer, as indicated by your tag. Within the item renderer, you could use Label components and set a selection of attributes that make them look like links, and then enable/disable them depending on your condition.

Here's some example code off the top of my head, with the following caveats:

  • I'm using an MX DataGrid instead of the Spark DataGrid.
  • I'm using an inline item renderer for convenience, but it is better practice to externalise your item renderers into separate MXML files.

    <mx:DataGrid id="dataGrid" dataProvider="{dataProvider}" ...>
        <mx:columns>
            <mx:DataGridColumn id="status_id_column" dataField="statusId" headerText="Status" />
            <mx:DataGridColumn id="action_column">
                <mx:itemRenderer>
                    <fx:Component>
                        <mx:Label text="View" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
                        <mx:Label text="Edit" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
                        <mx:Label text="Delete" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
                    </fx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>
    
我的痛♀有谁懂 2024-12-12 16:35:48

感谢avik的帮助,它是部分正确的,因为对我来说,有很多条件我不能将其放入启用属性中。无论如何,我从我这边得到了解决方案:)

这是语法。

    <mx:HBox width="100%">
   <mx:DataGrid id="reportDataGrid" dataProvider="{reportDataGridArrayCollection}"
         variableRowHeight="true" editable="false" rowHeight="75"
         width="100%" height="400" allowDragSelection="false"
         draggableColumns="false" textAlign="center">
    <mx:columns>
     <mx:DataGridColumn sortable="false" dataField="reportId" resizable="false" headerText="" width="0.06" editable="false" textAlign="center"/>
          <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="reportStatusId" headerWordWrap="true" headerText="Status" width="0.21">
     </mx:DataGridColumn>
     <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="lockedByUser" headerWordWrap="true" headerText="Locked (Worked) By" width="0.10"/>

     <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="" headerWordWrap="true" headerText="Acion" width="0.20">
      <mx:itemRenderer>
       <fx:Component>
        <mx:HBox textAlign="left" width="100%" creationComplete="init1()" > 
        <fx:Script> 
         <![CDATA[ 

          public function init1():void {
           if(data.reportStatusId==0) {
            viewLnk.visible = true;
            viewLnk.includeInLayout = true;
  // this is my condition which you can ignore....          if((data.entityId==1 || data.entityId==2 || data.entityId==3 || data.entityId==4)            ){
             editLnk.visible = true;
             editLnk.includeInLayout = true;
            }
           }
           if(data.reportStatusId==1 
             ) {
            editLnk.visible = true;
            editLnk.includeInLayout = true;
           }
           if(data.reportStatusId==2) {
            reviewLnk.visible = true;
            reviewLnk.includeInLayout = true;
           }
           if(data.reportStatusId==3) {
            saveXMLLnk.visible = true;
            saveXMLLnk.includeInLayout = true;
           }
          }
         ]]> 
        </fx:Script>
         <mx:LinkButton id="editLnk" visible="false" includeInLayout="false" label="Edit" click="outerDocument.editReport(data.reportId)"/>
         <mx:LinkButton id="viewLnk" visible="false" includeInLayout="false" label="View" click="outerDocument.viewReport(data.reportId)"/>
         <mx:LinkButton id="reviewLnk" visible="false" includeInLayout="false" label="Review" click="outerDocument.reviewReport(data.reportId)"/>
           <mx:LinkButton id="saveXMLLnk" visible="false" includeInLayout="false" label="Save XML" click="outerDocument.saveXMLReport(data.reportId)"/>

        </mx:HBox>
       </fx:Component>
      </mx:itemRenderer>
     </mx:DataGridColumn>
    </mx:columns>
   </mx:DataGrid>
  </mx:HBox>

thanks avik for your help it is partially correct as for me there are lot of condition i can not put that in enabled attribute. anyway i got the solution from my side :)

here is the syntax.

    <mx:HBox width="100%">
   <mx:DataGrid id="reportDataGrid" dataProvider="{reportDataGridArrayCollection}"
         variableRowHeight="true" editable="false" rowHeight="75"
         width="100%" height="400" allowDragSelection="false"
         draggableColumns="false" textAlign="center">
    <mx:columns>
     <mx:DataGridColumn sortable="false" dataField="reportId" resizable="false" headerText="" width="0.06" editable="false" textAlign="center"/>
          <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="reportStatusId" headerWordWrap="true" headerText="Status" width="0.21">
     </mx:DataGridColumn>
     <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="lockedByUser" headerWordWrap="true" headerText="Locked (Worked) By" width="0.10"/>

     <mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="" headerWordWrap="true" headerText="Acion" width="0.20">
      <mx:itemRenderer>
       <fx:Component>
        <mx:HBox textAlign="left" width="100%" creationComplete="init1()" > 
        <fx:Script> 
         <![CDATA[ 

          public function init1():void {
           if(data.reportStatusId==0) {
            viewLnk.visible = true;
            viewLnk.includeInLayout = true;
  // this is my condition which you can ignore....          if((data.entityId==1 || data.entityId==2 || data.entityId==3 || data.entityId==4)            ){
             editLnk.visible = true;
             editLnk.includeInLayout = true;
            }
           }
           if(data.reportStatusId==1 
             ) {
            editLnk.visible = true;
            editLnk.includeInLayout = true;
           }
           if(data.reportStatusId==2) {
            reviewLnk.visible = true;
            reviewLnk.includeInLayout = true;
           }
           if(data.reportStatusId==3) {
            saveXMLLnk.visible = true;
            saveXMLLnk.includeInLayout = true;
           }
          }
         ]]> 
        </fx:Script>
         <mx:LinkButton id="editLnk" visible="false" includeInLayout="false" label="Edit" click="outerDocument.editReport(data.reportId)"/>
         <mx:LinkButton id="viewLnk" visible="false" includeInLayout="false" label="View" click="outerDocument.viewReport(data.reportId)"/>
         <mx:LinkButton id="reviewLnk" visible="false" includeInLayout="false" label="Review" click="outerDocument.reviewReport(data.reportId)"/>
           <mx:LinkButton id="saveXMLLnk" visible="false" includeInLayout="false" label="Save XML" click="outerDocument.saveXMLReport(data.reportId)"/>

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