Jay Roy
asked on
merging cells in datagrid
hi guys
I have in my datagrid
col1 col2 col3
1 jay manager
1 ram CEO
2 Kris Developer
Is there any way i can merge the two cells in col1 into one cell which have same values?
my display should be
col1 col2 col3
1 jay manager
ram CEO
2 Kris Developer
col1 is merged for same value and '1' is shown only once
any idea how i can do that?
thanks
I have in my datagrid
col1 col2 col3
1 jay manager
1 ram CEO
2 Kris Developer
Is there any way i can merge the two cells in col1 into one cell which have same values?
my display should be
col1 col2 col3
1 jay manager
ram CEO
2 Kris Developer
col1 is merged for same value and '1' is shown only once
any idea how i can do that?
thanks
Use Adobe AdvancedDataGrid and GroupCollection
ASKER
Can you please provide a sample code
ASKER
Basically I am looking for a ItemRenderer which will do the grouping based on 'col1'
and i can say
colunm.setItemRenderer(Ite mrenderer)
and i can say
colunm.setItemRenderer(Ite
ASKER
I have comeup with something..can you please advice
My renderer which will do the grouping is TradeGroupingRenderer
and i am calling like this
public class TradeGrid extends VBox{
private function buildColumnModel(complexhe aders:Obje ct,fields: Object):vo id{
dataGrid.rendererProviders = new ClassFactory(TradeGrouping Renderer );
}
}
My renderer which will do the grouping is TradeGroupingRenderer
public class TradeGroupingRenderer extends HBox implements IDropInListItemRenderer{
protected var _listData:DataGridListData;
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
invalidateProperties();
}
public function TradeGroupingRenderer()
{
super();
var matrixGrid:AdvancedDataGrid = AdvancedDataGrid(DataGridListData(_listData).owner);
var myGroup:Grouping = new Grouping();
myGroup.fields = [new GroupingField("col1")];
var myGroupColl:GroupingCollection = new GroupingCollection();
myGroupColl.source = new ArrayCollection(matrixGrid.dataProvider); //error on this line
myGroupColl.grouping = myGroup;
myGroupColl.refresh();
matrixGrid.dataProvider = myGroupColl;
}
}
and i am calling like this
public class TradeGrid extends VBox{
private function buildColumnModel(complexhe
dataGrid.rendererProviders
}
}
Try without explicite setting of ArrayCollection
package{
import mx.collections.ArrayCollec tion;
import mx.collections.Grouping;
import mx.collections.GroupingCol lection;
import mx.collections.GroupingFie ld;
import mx.containers.HBox;
import mx.controls.AdvancedDataGr id;
import mx.controls.dataGridClasse s.DataGrid ListData;
import mx.controls.listClasses.Ba seListData ;
import mx.controls.listClasses.ID ropInListI temRendere r;
public class TradeGroupingRenderer extends HBox implements IDropInListItemRenderer{
protected var _listData:DataGridListData ;
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListDat a):void
{
_listData = DataGridListData(value);
invalidateProperties();
}
public function TradeGroupingRenderer()
{
super();
var matrixGrid:AdvancedDataGri d = AdvancedDataGrid(DataGridL istData(_l istData).o wner);
var myGroup:Grouping = new Grouping();
myGroup.fields = [new GroupingField("col1")];
var myGroupColl:GroupingCollec tion = new GroupingCollection();
myGroupColl.source = matrixGrid.dataProvider; //error on this line
myGroupColl.grouping = myGroup;
myGroupColl.refresh();
matrixGrid.dataProvider = myGroupColl;
}
}
}
package{
import mx.collections.ArrayCollec
import mx.collections.Grouping;
import mx.collections.GroupingCol
import mx.collections.GroupingFie
import mx.containers.HBox;
import mx.controls.AdvancedDataGr
import mx.controls.dataGridClasse
import mx.controls.listClasses.Ba
import mx.controls.listClasses.ID
public class TradeGroupingRenderer extends HBox implements IDropInListItemRenderer{
protected var _listData:DataGridListData
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListDat
{
_listData = DataGridListData(value);
invalidateProperties();
}
public function TradeGroupingRenderer()
{
super();
var matrixGrid:AdvancedDataGri
var myGroup:Grouping = new Grouping();
myGroup.fields = [new GroupingField("col1")];
var myGroupColl:GroupingCollec
myGroupColl.source = matrixGrid.dataProvider; //error on this line
myGroupColl.grouping = myGroup;
myGroupColl.refresh();
matrixGrid.dataProvider = myGroupColl;
}
}
}
In my opinion you can solve using datagrid and inspecting data you are going to show like described in this article:
http://www.adobe.com/devne t/flex/art icles/item renderers_ pt1.html
You should check if data in column1 is the same like the previous item, you can recover index of an element inside itemrenderer using ItemIndex property
http://help.adobe.com/en_U S/FlashPla tform/refe rence/acti onscript/3 /spark/com ponents/su pportClass es/ItemRen derer.html #itemIndex
if you need index of previous item it will be itemIndex-1.
With an if statement inside itemrenderer for col1 you can choose if write the number or an empty string, and/or apply a certain style or a different one .
Let me know if it's been an useful suggestion.
Regards
http://www.adobe.com/devne
You should check if data in column1 is the same like the previous item, you can recover index of an element inside itemrenderer using ItemIndex property
http://help.adobe.com/en_U
if you need index of previous item it will be itemIndex-1.
With an if statement inside itemrenderer for col1 you can choose if write the number or an empty string, and/or apply a certain style or a different one .
Let me know if it's been an useful suggestion.
Regards
ASKER
Actually I don't need the grouping functionality
So I won't be using Groupingcollection. I just want to use
Arraycollection.
Coming back to my original question , I just want to
Display '1' just once under col1 and merge the two cells with value 1.
I am not sure how to merge the two cells into one cell.
Any code would help.
So I won't be using Groupingcollection. I just want to use
Arraycollection.
Coming back to my original question , I just want to
Display '1' just once under col1 and merge the two cells with value 1.
I am not sure how to merge the two cells into one cell.
Any code would help.
If you want to use Tree structure you should use HistoricalData or GroupCollection
Otherwise you can create a filter function for removing element from a column and display as DataGrid (not tree)
Otherwise you can create a filter function for removing element from a column and display as DataGrid (not tree)
ASKER
Using filter function will I be able to merge the cells into one cell?
An example would help.
Thx
An example would help.
Thx
ASKER
For example in the below grid
col1 col2 col3
1 jay manager
1 ram CEO
2 Kris Developer
how can i use filter function to remove the duplicate values under col1 and how can i merge the
cells which have duplicate values..
thanks
col1 col2 col3
1 jay manager
1 ram CEO
2 Kris Developer
how can i use filter function to remove the duplicate values under col1 and how can i merge the
cells which have duplicate values..
thanks
ASKER
My code is
private var dataCollection:ArrayCollec tion = new ArrayCollection();
dataCollection.addItem(Obj ect1); //contains 1 jay manager
dataCollection.addItem(Obj ect2); //contains 1 ram CEO
dataCollection.addItem(Obj ect3); //contains 2 Kris Developer
this.dataGrid.dataProvider = dataCollection;
this.dataGrid.visible = true;
private var dataCollection:ArrayCollec
dataCollection.addItem(Obj
dataCollection.addItem(Obj
dataCollection.addItem(Obj
this.dataGrid.dataProvider
this.dataGrid.visible = true;
Yes, you can.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="alert()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dataCollection:ArrayCollection = new ArrayCollection();
private function alert():void {
dataCollection.addItem({col1:1, col2:'jay', col3:'manager'}); //contains 1 jay manager
dataCollection.addItem({col1:1, col2:'ram', col3:'CEO'}); //contains 1 ram CEO
dataCollection.addItem({col1:2, col2:'Kris', col3:'Developer'}); //contains 2 Kris Developer
var map:Object = {};
dataCollection.filterFunction = function(item:Object):Boolean {
if (!map[item.col1]){
map[item.col1] = true;
}else{
item.col1 = "";
}
return true;
};
dataCollection.refresh();
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{dataCollection}">
<mx:columns>
<mx:DataGridColumn dataField="col1"/>
<mx:DataGridColumn dataField="col2"/>
<mx:DataGridColumn dataField="col3"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
ASKER
thanks
I was able to remove the duplicates with your code, but i am still not able to merge the cells
I was able to remove the duplicates with your code, but i am still not able to merge the cells
How u can merge they are rows
ASKER
Do i have to create CSS to merge the cells into one cell ?
thanks
thanks
You can merging cells in ADG by using colSpan
ASKER
Do i have to create iremRenderer and set the iremrenderer to the column? and use the colSpan in
Itemrenderer ?
Some sample code would be helpful
Itemrenderer ?
Some sample code would be helpful
ASKER
something like...
private function createColumn(columnIndex:i nt,fieldOb ject:Objec t):Advance dDataGridC olumn{
if(columnIndex == 1){ //dataField="col1"
column.itemRenderer = new ClassFactory(MergeCellsRen derer);
}
public class MergeCellsRenderer{
how to use colSpan here?
}
private function createColumn(columnIndex:i
if(columnIndex == 1){ //dataField="col1"
column.itemRenderer = new ClassFactory(MergeCellsRen
}
public class MergeCellsRenderer{
how to use colSpan here?
}
You still didn't tell me how would you like to merge columns
Draw an image
Draw an image
ASKER
I want to merge the cells under column
Under Id column i want to merge cell1 (which contains 100), cell2 (contains blank) and cell3 which (contains blank)
Under Id column i want to merge cell1 (which contains 100), cell2 (contains blank) and cell3 which (contains blank)
ASKER
ASKER
well its not a big difference . You see the alternating colors under Id column? I just want a single color (white) for the first three cells under Id column in my image.
thx
thx
You can remove alternating colors using CSS
ASKER
can you just provide the code how i can do that
thanks
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.