Basically what I want to do is to select just one cell, and let the information about that cell being displayed as either a label in the box under it.
This is what I have at the moment:
<s:DataGrid selectionMode="multipleCells" x="726" y="0" width="446" height="50" requestedRowCount="0" click="itemClickEvent(event)">
<s:columns>
<s:ArrayList>
<s:GridColumn width="63" dataField="dataField1" headerText="見積条件"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField2" headerText="原価見積"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField3" headerText="見積作成"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField4" headerText="見積発行"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField5" headerText="受注失注"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField6" headerText="納品"></s:GridColumn>
<s:GridColumn width="63" dataField="dataField7" headerText="請求"></s:GridColumn>
</s:ArrayList>
</s:columns>
<s:ArrayList>
<fx:Object dataField1="2" dataField2="1" dataField3="2" dataField4="1" dataField5="4" dataField6="1" dataField7="1"></fx:Object>
</s:ArrayList>
</s:DataGrid>
private function itemClickEvent(event:Event):void
{
currentState='information_dropdown'
Alert.show("Row : " +event.rowIndex + "Column : " +event.columnIndex)
}
Although the code shows an alert box I want to display it as a label under it instead. I do get an error on the rowIndex and columnIndex part.
Any advice would be great.
Instead of listening for click event on datagrid, listen for GridEvent.GRID_CLICK:
<s:DataGrid selectionMode="multipleCells" x="726" y="0" width="446" height="50" requestedRowCount="0" gridClick="itemClickEvent(event)">
And change listener argument type to GridEvent:
private function itemClickEvent(event:GridEvent):void
{
...
}
rowIndex and columnIndex should then give proper results.
Related
Can we provide 2 data providers at a same time in a data grid in flex 4. If yes, how ? Please explain with example.
<s:DataGrid id="dgDest" dataProvider="{destProds && ??}" width="100%" height="100%" editable="true"
selectionMode="multipleRows"
gridItemEditorSessionStarting="dgDest_gridItemEditorSessionStartingHandler(event)"
paste="dgDest_pasteHandler(event)"
>
<s:columns>
<s:ArrayList>
<!--<s:GridColumn width="20" dataField="MNF_DESC" sortCompareFunction="{sortNumeric('MNF_DESC')}" headerText="Manufacturer"
headerRenderer="{new ClassFactory(styleManager.getStyleDeclaration('.generic').getStyle('spreadHeaderRenderer'))}"/>-->
<s:GridColumn width="20" dataField="MNF_DESC" sortCompareFunction="{sortNumeric('MNF_DESC')}" headerText="Manufacturer"
headerRenderer="{ new ClassFactory(styleManager.getStyleDeclaration('.generic').getStyle('spreadHeaderRenderer'))}" />
<s:GridColumn dataField="PRODUCT_DESC" headerText="Products" editable="true"
headerRenderer="{ new ClassFactory(styleManager.getStyleDeclaration('.generic').getStyle('spreadHeaderRenderer'))}"/>
<s:GridColumn dataField="PACK_DESC" headerText="Packs" editable="false"
headerRenderer="{ new ClassFactory(styleManager.getStyleDeclaration('.generic').getStyle('spreadHeaderRenderer'))}"/>
<s:GridColumn dataField="NDF_CODE" headerText="NDF No." width="80" editable="false"
headerRenderer="{ new ClassFactory(styleManager.getStyleDeclaration('.generic').getStyle('spreadHeaderRenderer'))}"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
I tried like this but this is not working. please explain how this could be possible.
A Spark DataGrid cannot take 2 dataProviders.
If you need to merge the data, do it before you pass it to the DataGrid, on the server code or in the client code.
I want to delete all selected rows in a Spark datagrid.
This code below accounts for the Vector indices but I cannot get it to work. It does not throw out any errors.
What am I doing wrong?
public function deleteItem(event:MouseEvent):void{
var sIndices:Vector.<int> = arrayGrid.selectedIndices;
sIndices.sort(Array.NUMERIC);
for(var index:int = sIndices.length-1; index>=0; index--) {
arrayColl.removeItemAt(sIndices[index]);
}
arrayColl.refresh();
}
private function convertDateFormat(item:Object,column:GridColumn):String {
return simpleDate.format(item.itemStartDate);simpleDate.format(item.itemEndDate);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" >
<s:Button label="Remove Selected Items"/>
<s:Button label="Add New Entry" click="newItem()"/>
<search:searchBar id="SearchBar" searchListCollection="{arrayColl}"
dataGrid="{arrayGrid}"/>
<s:DataGrid id="arrayGrid" width="100%" height="100%" dataProvider="{arrayColl}"
selectionMode="multipleRows" doubleClickEnabled="true">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="projectName" headerText="Project Name" />
<s:GridColumn dataField="tag" headerText="Priority Code" />
<s:GridColumn width="180" dataField="itemStartDate"
labelFunction="convertDateFormat" headerText="Start Date"/>
<s:GridColumn width="180" dataField="itemEndDate"
labelFunction="convertDateFormat" headerText="End Date"/>
<s:GridColumn dataField="notes" headerText="Notes"/>
<s:GridColumn width="100" dataField="colorCode" headerText="Color HEX"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
It looks like you forgot to call the deleteItem method.
<s:Button label="Remove Selected Items" click="deleteItem(event)"/>
I have a strange problem in Flex. I have a ButtonBar with 7 buttons and always the fifth is invisible. Even when I switch places of buttons always the one which is the fifth is the one I cannot see.
Here is my code:
<s:HGroup x="6" y="6" visible="{entityId > 0}">
<mx:ButtonBar height="20" x="10" horizontalGap="4" itemClick="onButtonBarClickHandler(event)" id="buttonBar">
<mx:dataProvider>
<s:ArrayList>
<fx:Object label="xxx" action="AddItem" icon="{_addIcon}" />
<fx:Object label="zzz" action="DeleteItem" icon="{_deleteIcon}" enabled="{_dg.selectedItem as TemplateFile != null}" />
<fx:Object label="yyy" action="Generate" enabled="{_dg.selectedItem.IsTemplate}" />
<fx:Object label="aaa" action="PublishSharePoint" enabled="{_dg.selectedItem.IsTemplate}" />
<fx:Object label="bbb" action="SetDefault"/>
<fx:Object label="Download document" action="DownloadDocument"/>
<fx:Object label="Show Tags" action="ShowTags"/>
</s:ArrayList>
</mx:dataProvider>
</mx:ButtonBar>
</s:HGroup>
Do you have any idea what is wrong here?
Tried to reproduce it, no success - they are all visible.
My guess is that you have some code that causes it to become invisible.
I m trying to add a textInput in the datagrid so that users can see that there is a textbox for them to edit. I have a textInputRender so that I can show the textbox in the dataGrid and update the value accordingly.
I also have another dataGrid table to capture the values I have selected in the previous dataGrid table.
The problem is I am able to see the textbox in the dataGrid table. But I have to double click the cell and enter my value to save the value of the cell in the dataGrid back to the data provider.In reality the user will not double click to enter as they might just enter the value in. Is there a way to capture the value without double clicking the cell ??
Next problem after I double click the textBox and enter my new value for the quantity it do not reflect the change in the textbox. But however I can see that the newly entered value is captured.
Pls help me. I have been sruggling with this for very long. Pls can u tell me how I can slove this ?
This is my custom renderer of the textbox I place it within the GridItemRenderer tags :
<s:TextInput id="ti" text="{data.quant}"/>
This is my code:
<fx:Script>
<![CDATA[
import FrontEndObjects.ColourItems;
import mx.collections.ArrayCollection;
import spark.events.IndexChangeEvent;
[Bindable]
private var order:ArrayCollection = new ArrayCollection();
private function addOrder():void{
var orderItems:ColourItems = new ColourItems("OrderNo","1","--Choose a colour--");
order.addItem(orderItems);
}
[Bindable]
private var confirmOrder:ArrayCollection = new ArrayCollection();
protected function saveData(event:MouseEvent):void
{
//dataGrid is the id (name) of our dataGrid table
var dataProvider = myDG.dataProvider;
var item = null;
for (var i:int = 0; i < dataProvider.length; i++)
{
item = dataProvider.getItemAt(i);
confirmOrder.addItem(item);
//Alert.show("the data is : " + item);
}
}
]]>
</fx:Script>
<s:BorderContainer x="240" y="50" width="449" height="518">
<s:DataGrid id="myDG" x="32" y="27" width="393" height="151" dataProvider="{order}"
editable="true" variableRowHeight="true">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="label1" headerText="Order #" editable="false"/>
<s:GridColumn dataField="quant" headerText="Qty" editable="true" itemRenderer="DesignItemRenderer.myTextInputRender"/>
<s:GridColumn dataField="color" headerText="Color" editable="true" rendererIsEditable="true">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
protected function onCbChange(event:IndexChangeEvent):void
{
var value:String = (event.currentTarget as DropDownList).selectedItem;
data[column.dataField] = value;
}
]]>
</fx:Script>
<s:DropDownList id="cb" width="100%" change="onCbChange(event)" prompt="--Choose a colour--"> <!--selectedIndex="0" requireSelection="true" >-->
<s:dataProvider>
<s:ArrayCollection>
<fx:String>red</fx:String>
<fx:String>blue</fx:String>
<fx:String>green</fx:String>
</s:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayList>
</s:columns >
</s:DataGrid>
<s:DataGrid id="myDG1" x="24" y="317" width="401" height="174" dataProvider="{confirmOrder}"
requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="label1" headerText="Ordernum - getback"></s:GridColumn>
<s:GridColumn dataField="quant" headerText="quanty-getback"></s:GridColumn>
<s:GridColumn dataField="color" headerText="color-getback"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button x="355" y="186" label="add" click="addOrder()" />
<s:Button x="277" y="186" label="save" click="saveData(event)"/>
</s:BorderContainer>
Try this:
Set rendererIsEditable="true" in your GridColumn "quant"
<s:GridColumn dataField="quant" headerText="Qty" editable="true" rendererIsEditable="true" itemRenderer="DesignItemRenderer.myTextInputRender"/>
Change your ItemRenderer like this
<?xml version="1.0" encoding="utf-8"?>
<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:Binding source="ti.text" destination="data.quant"/>
<s:TextInput
id="ti"
text="{data.quant}"
editable="true"/>
</s:GridItemRenderer>
It works by me fine
I can't recognize which is the problem with your code anyway I managed to develop a:
textInput in the datagrid so that users can see that there is a
textbox for them to edit
Using this code
<mx:DataGrid id="weekGrid" width="100%" height="60%"
dataProvider="{weekList}" editable="true">
<mx:DataGridColumn id="noteColumn" dataField="note" editable="false"
headerText="Note" sortable="false">
<mx:itemRenderer>
<fx:Component>
<mx:VBox width="100%" height="100%" horizontalAlign="center"
verticalAlign="middle">
<fx:Script>
<![CDATA[
import managers.StraordinariManager;
import spark.events.TextOperationEvent;
protected function textinput1_changeHandler(event:TextOperationEvent):void
{
data['note']=textInput.text;
outerDocument.notSavedAlert.statrtBlinker();
}
]]>
</fx:Script>
<s:TextInput id="textInput" width="100%" height="100%"
borderVisible="false"
change="textinput1_changeHandler(event)"
editable="{data.oreStr!=null}"
text="{data.oreStr!=null?data.note:''}">
</s:TextInput>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:DataGrid>
I used an ItemRenderer instead of a ItemEditor to avoid the double click problem.
Notice that the column editable property is set to false, but the grid is set to editable="true".
I also used the same tecnique to insert also different components, this is an example using the radio button:
<mx:DataGridColumn id="flag" headerText="Approva Rifiuta" >
<mx:itemRenderer>
<fx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center"
verticalAlign="middle">
<fx:Script>
<![CDATA[
import managers.IngressiManager;
import mx.events.FlexEvent;
protected function radiobutton1_changeHandler(event:Event):void
{
if(apprRb.selected){
data['flag']=ApprovazioneStraordinariView.APPROVA_FLAG;
data['note']="";
}else
if(rifRb.selected){
data['flag']=ApprovazioneStraordinariView.RIFIUTA_FLAG;
}
}
]]>
</fx:Script>
<s:RadioButton id="apprRb" label="A"
click="radiobutton1_changeHandler(event)"
groupName="approvaRifiutaGroup"
selected="{data['flag']==ApprovazioneStraordinariView.APPROVA_FLAG}">
</s:RadioButton>
<s:RadioButton id="rifRb" label="R"
click="radiobutton1_changeHandler(event)"
groupName="approvaRifiutaGroup"
selected="{data['flag']==ApprovazioneStraordinariView.RIFIUTA_FLAG}">
</s:RadioButton>
<fx:Declarations>
<s:RadioButtonGroup id="approvaRifiutaGroup">
</s:RadioButtonGroup>
</fx:Declarations>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
I have a list that as an arraylist as a dataprovider.It has an inline item renderer thet has image control. The click event doesn't work for the image ctrl.The code looks like this
<s:ArrayList id="allActionsArrList">
<fx:Object click="showList('Portlet')" source="#Embed('images/bpc1.jpg')" />
<fx:Object click="showList('Pages')" source="#Embed('images/Tab.png')" />
<fx:Object click="smsClick()" source="#Embed('images/launchpad_tel.png')" />
<fx:Object click="logoutImg_clickHandler(event)" source="#Embed('images/logoutS.swf')" />
</s:ArrayList>
<s:List id="actionStripList" bottom="0" width="100%" borderColor="black"
borderVisible="true" contentBackgroundAlpha="0" dataProvider="{allActionsArrList}"
useVirtualLayout="false">
<s:layout>
<s:TileLayout/>
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer width="100%" height="40">
<mx:Image buttonMode="true" horizontalCenter="0"
width="40" height="40" source="{data.source}" click="{data.click}"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
Any idea.Thanks in advance!
1.You may do something like this:
<fx:Object clickHandler="{showList}" clickParams="{['Portlet']}" source="#Embed('images/bpc1.jpg')" />
<fx:Object clickHandler="{showList}" clickParams="{['Pages']}" source="#Embed('images/Tab.png')" />
<fx:Object clickHandler="{smsClick}" clickParams="{[]}" source="#Embed('images/launchpad_tel.png')" />
<fx:Object clickHandler="{logoutImg_clickHandler}" clickParams="{[]}" source="#Embed('images/logoutS.swf')"/>
<mx:Image buttonMode="true" horizontalCenter="0" width="40" height="40" source="{data.source}" click="data.clickHandler.apply(this, data.clickParams)"/>
Here you possibly should take care of this object (info)
But I'd used the 2nd variant.
2.Another variant is to define some attribute (id for example) for your Object items. Then you can use switch statement in your inline itemRenderer and call different listeners depending on data.id.