Adding a dynamic summary row for a spark data grid

i'm looking for a solution for a spark data grid.
by clicking on a row it will become larger and will show under the original row a some kind of a summary text with no realtion to columns.
is there a summary row option for a spark datagrid that can shown by clicking on the row?

Why would you need to make this part of the DataGrid? Just create some kind of view and bind it's data to the selectedItem of the DataGrid.
*edit*
Ohhhh, I see that you want it to display under the item. I believe you can do what you need in the skin, but I haven't had a chance to use the spark DataGrid yet so I can't say for sure. I know it has a feature to skin the selection, so I'm sure you can use that to do what you need.

Similar Messages

  • My custom Tool tip on spark data Grid don't work ?

    I want to add panel component as my tooltip for each row in my Spark DataGrid. So when mouse rollover the user can see the information for each the ship. I want a panel as my tooltip for dataGrid cause I want to organize my data neatly and also place a image in the panel.
    I came across :http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60d65-7ff6.html  where they show an example of "Implementing the IToolTip interface" using the panel.I tried manipulating the codes but it didt work for my spark dataGrid.
    So my question :
    Can some one pls show me how I can use the Panel as my tool tip for each row in spark data grid.
    I have been struggling for quite some time.If possible pls Give me an example.
    This is my codes below (I tried to follow the example from :http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf60d65-7ff6.html#WS2d b454920e96a9e51e63e3d11c0bf60d65-7ff4 -"Implementing the IToolTip interface")
    My MXML Application codes :
        <fx:Script>
        <![CDATA[
            import DesignItemRenderer.PanelToolTip;
            import mx.events.ToolTipEvent;
            import mx.collections.ArrayCollection;         
            import mx.controls.Alert;  
            import spark.events.GridEvent; 
            [Bindable]
            private var myArrivalShips:ArrayCollection = new ArrayCollection([
                {arrivalShipsName:"Ship A", ETD:"12 March"},
                {arrivalShipsName:"Ship B", ETD:"25 March"}            
            private function createCustomTip(event:ToolTipEvent):void {
                var ptt:PanelToolTip = new PanelToolTip();
                ptt.title = "my Ship Info";
                ptt.bodyText = "my data for the ship";
                event.toolTip = ptt;
        ]]>
    </fx:Script>
    <s:BorderContainer x="267" y="11" width="331" height="586">
        <s:DataGrid id="arrivalTable" x="10" y="326" width="302" height="205" requestedRowCount="4" dataProvider="{myArrivalShips}" toolTipCreate="createCustomTip(event)">
            <s:columns>
                <s:ArrayList>
                    <s:GridColumn dataField="arrivalShipsName" headerText="Arrival Ships" ></s:GridColumn>
                    <s:GridColumn dataField="ETD" headerText="ETD"></s:GridColumn>             
                </s:ArrayList>
            </s:columns>           
        </s:DataGrid>
        <s:BorderContainer x="10" y="19" width="302" height="285">
        </s:BorderContainer>
    </s:BorderContainer>
    My Custom Panel codes :
    <s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
         implements="mx.core.IToolTip" >
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            [Bindable]
            public var bodyText:String = "";
            //  Implement required methods of the IToolTip interface; these
            //  methods are not used in this example, though.
            public var _text:String;
            public function get text():String {
                return _text;
            public function set text(value:String):void {
        ]]>
    </fx:Script>
    <s:RichText text="{bodyText}" percentWidth="100"/>
    </s:Panel>

    Ok I was getting ready to post the renderer code and then found the problem. I had copied this code from another renderer which had contentBackgroundAlpha=0 in the MXAdvancedDataGridItemRenderer tag. When I removed it, the style of the TextArea worked as intended. Your comment helped me to take a closer look at the renderer code, so thank you.

  • Update one row at a time, Data Grid

    Is it possible to update one row of a mx:DataGrid at a time.  I want to be able to have a user push a button and info populates one row of the data grid, user changes some properties and pushes the button again and another row of values populate the DataGrid.  Everything I see does a mass population from an XML or what have you.
    Thanks

    I did this this to work, so for those of you who may find this info helpfull here is how I solved the issue.
    I instantiated an ArrayCollection object like so:
    private var _rowValues:ArrayCollection = new ArrayCollection();
    I simply referenced the .addItem() property of my ArrayCollection.
    I then added values to the ArrayCollection as follows
    _rowValues.addItem({Ingredient:ingredient, Amount:amount, Category:category}); //dataField:value
    and referenced the dataField proerpty of the DataGrid... so in my case my 3 dataField properties (in my mxml compontent) were as fillows:
    dataField="Ingredient"
    dataField="Amount"
    dataField="Category"
    all done, and it works.

  • Bind one column to two fields in spark data grid

    hi,
    igave a spark datagrid that uses a GridItemRenderer with a RichText label display.
    the RichText column needs to display two or more fields in diffrenet sizes and colors.
    how can i bind the column to two or more fields?
    any help would be great.

    yes.
    my label function is:
    private function list_labelFunc(item:Object, column:GridColumn):String{
    var result:String = '<span fontSize="12">'+item.InstrumentName+'</span>'; 
    result +=
    '<span color="#FF0000">'+item.SystemName+'</span>'; 
    return result; 
    /* return markupSystem.replace("INSTRUMENTNAME",data.InstrumentName).replace("SYSTEMNAME",data.Syst emName)); */
    my grid column defenition  is:
    <s:GridColumn id="colName" labelFunction="list_labelFunc" headerText="Name" itemRenderer="renderers.OpenPositionsItemRenderer" >
    and my item renderer is:
    <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:Script>
    <![CDATA[
     import mx.collections.ArrayCollection; 
    import spark.components.Grid; 
    import flashx.textLayout.elements.TextFlow; 
    import spark.utils.TextFlowUtil; 
    var markupSystem:String = "<p>INSTRUMENTNAME</p><p>SYSTEMNAME</p>"; 
    override public function prepare(hasBeenRecycled:Boolean):void {lblData.text = data[column.dataField]
    override public function set data(value:Object):void{
    var myOwner = super.grid as Grid;  
    super.data = value; 
    var myOwnerDataProvider:ArrayCollection = myOwner.dataProvider as ArrayCollection; 
    var myIndex:int = myOwnerDataProvider.getItemIndex( data ); 
    var i : uint; 
    if(myOwner.selectedIndex !=myIndex){
    if(myIndex % 2 == 0){
    c.color=0x525252;
    else{
    c.color=0x2C2C2C;
    else 
    c.color=0x355180;
    if(column.columnIndex==1){
    var flow:TextFlow = TextFlowUtil.importFromString(markupSystem.replace("INSTRUMENTNAME",data.InstrumentName).replace("SYSTEMNAME",data.SystemName));lblData.textFlow = flow;
    ]]>
    </fx:Script>
     <s:Rect id="rect" top="0" bottom="0" right="0" left="0">
     <s:fill>
     <s:SolidColor id="c" color="#2C2C2C"/>
     </s:fill>
     </s:Rect>
     <s:RichText id="lblData" textAlign="center" color="#DADADA" alpha="0.5" top="20" left="20"/></s:GridItemRenderer>

  • Dynamic Header row for table not aligned properly on 2nd Page

    Hello Friends,
    The problem is like this :
    We have a table with dynamic number of columns and few of them are being hidden at runtime based on a configuration table.
    Now problem while printing is that first page is printing the header row, but same is not being repeated on subsequent pages.
    Please see the layout
    Header row is warped in 2 subforms both are flowed - western text so that they will get squeezed if column is hidden
    Here are the properties for subforms
    1) overflowLeader => Flow top-bottom
    2) OF_SF => Flowed , western text
    On 2nd page all the columns are getting aligned to left hand side whereas printing fine on first page.
    Thanks,
    Nitin

    Hi Nitin,
    in this case, you must use more nested wrapper subforms and set the root subform layout from "flow" to "positioned". I cannot give advice on how the wrapper subforms are organized, since it depends on your logic, just try it out.
    Cheers,
    Tao

  • Adding tabs dynamically at runtime for a tab navigator control

    Hi,
    Is it possible in flex builder 2 to dynamically add the tabs
    at runtime to the tab navigator control, if we can add plz tell the
    procedure to do that
    thanks in advance

    Given that you had a tab navigator declared in mxml like
    this:
    <mx:TabNavigator id="myTabber" selectedIndex="0">
    </mx:TabNavigator>
    you should just be able to call the addChild method, passing
    the child tab containers. So for example, in some ActionScript
    event handler:
    var newTab:Canvas = new Canvas();
    myTabber.addChild(newTab);
    bear in mind I haven't done this by adding tabs, but have
    done tons with adding controls to an application at runtime using
    this method (DataGrids, Grid, GridItems, etc...)
    Jason

  • How to use one dynamic connection managers for multiple parallel data flow tasks

    hi there:
       I have 6 databases residing on the same server. What I want to do is  call a store procedure with identical name on each database dbo schema and transport results to a centralized place. The key is to have those SPs run in parallel instead
    of in sequence as each SP may take around 10 mins to finish. 
    The simplest way is to create 6 OLE DB connection managers and create 6 DFT tasks. However, I do not want to maintain 6 OLE DB connection managers as there is a chance to have more connection  managers.
     What I did so far is to create a OLD DB connection manager and use expression to set up connectionString properties so that it will get populated by variables at run time. It is fine when running all SPs in a Foreach Loop Container. However, it takes
    around 60 mins to finish.
      When I try to run it in parallel ( basically created 6 DFTs but use only one Dynamic Connection Manager), the connection string gets confused therefore all DFT tasks failed.
       Does anyone here have some experience on this topic?
    Thanks
     hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Yes, basically, on the connectionString property of ONE OLEDB, you are using an expression to supply value and this expression is pointing to a variable. 
    In this case , you can update this variable from a table which contains many connection strings. It's good if you want to execute Store procedures in a sequential order. When in parallel mode, this will cause issues as connectionString gets overwritten. 
     I am thinking about using script task to exec sp.
     The whole idea is that I do not want to maintain a large number of Connection Managers. 
    Hope it helps
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --
    So you are not able to run parallel executions using same conn mgmr, even with dynamic connectionstring, is that correct? Yes, script task will be a way to go if you wish to execute it in parallel, you may connect to SS and query the proper conn string with
    SELECT/WHERE clause in each script > pass it to a script variable > use that script variable and execute the proc. This will require only two things to change in each script, the WHERE condition to get the conn string and the proc name (you may even
    get the proc names the same way you get conn string) and everything else will be same. Let us know how that goes. 
    Hope no two or more procs doing insert/update/delete on the same tables.

  • Row Span in Advanced data Grid component

    Hi,
    I have tried to span rows in advancedDatagrid,can anyone help me with an example.
    Thanks,
    Chandrasekhar

    Thanks for the reply, but below is the format I am looking for in Datagrid spanning rows.
    Region
    Territory
    Territory Rep
    Actual
    Estimate
    Region1
    Territory1
    Territory Rep1
    100
    100
    Territory2
    Territory Rep2
    100
    100
    Territory3
    Territory Rep3
    100
    100
    Territory4
    Territory Rep4
    100
    100
    Territory5
    Territory Rep5
    100
    100
    Territory6
    Territory Rep6
    100
    100
    Territory7
    Territory Rep7
    100
    100
    Thanks,
    Chandrasekhar.

  • Dynamic add row/columns to data forms(11.1.1.3) v/s (11.1.2.1)

    Hello All,,
    There used to be an option in Hyperion planning 11.1.1.3 to Dynamic add rows in data form. I don't see this option in planning 11.1.2.1 ?
    Could you please suggest how we can grant right users to add dynamic add rows and columns in data forms? or it is possible in 11.1.2.1 ?
    out user want to have a feature of adding row in data forms (planning forms)
    Thank you
    Edited by: 842804 on Aug 17, 2011 12:49 PM

    Do you mean 11.1.2, if so then adhoc web forms really take over from adding rows as they add much more functionality.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • AdvancedDataGrid Summary Row Max Function

    I am trying to mix summary function within an advanced data grid.   I'm trying to use the SUM function at the highest grouping level (Southwest).  And a MAX function at the sub regional level (Arizona, Central California, etc).    I want the SUM function at the Southwest level to add the results of the MAX functions from the sub regional level.   Is this possible?

    You can do something like this in order to get SUM function
    <!--  The grid -->
        <mx:AdvancedDataGrid  id="adg"
                width="100%" height="100%">
            <!-- Define grouping in dataProvider  -->
            <mx:dataProvider>
                <!-- Convert flat data to group  -->
                <mx:GroupingCollection  id="gc"
                        source="{svc.getOrders.lastResult}">
                    <mx:Grouping>
                        <!-- First group by customer -->
                        <mx:GroupingField name="CUSTOMER">
                            <!-- Calculate total per customer  -->
                            <mx:SummaryRow summaryPlacement="group">
                                <mx:fields>
                                    <mx:SummaryField dataField="PRICE"
                                                    operation="SUM"
                                                    label="Total"/>
                                </mx:fields>
                            </mx:SummaryRow>
                        </mx:GroupingField>
                        <!-- Then group by orderid -->
                        <mx:GroupingField name="ORDERID">
                            <!-- Calculate total per orderid  -->
                            <mx:SummaryRow summaryPlacement="group">
                                <mx:fields>
                                    <mx:SummaryField dataField="PRICE"
                                                    operation="SUM"
                                                    label="Total"/>
                                </mx:fields>
                            </mx:SummaryRow>
                        </mx:GroupingField>
                    </mx:Grouping>
                </mx:GroupingCollection>
            </mx:dataProvider>
            <!-- The grid columns-->
            <mx:columns>
                <!-- Empty colume for tree -->
                <mx:AdvancedDataGridColumn />
                <!-- Query columns -->
                <mx:AdvancedDataGridColumn  dataField="CUSTOMER"
                    headerText="Customer" />
                <mx:AdvancedDataGridColumn  dataField="ORDERID"
                    headerText="Order"/>
                <mx:AdvancedDataGridColumn  dataField="ARTNAME"
                    headerText="Item" />
                <mx:AdvancedDataGridColumn  dataField="PRICE"
                    headerText="Price" textAlign="right" />
                <!-- Column for calculated totals  -->
                <mx:AdvancedDataGridColumn  dataField="Total"
                    headerText="Total" textAlign="right" />
            </mx:columns>
        </mx:AdvancedDataGrid>

  • Importing multiple rows from the same date from one table to another.

    I need to pull information from one sheet(Sheet 1) to another (Sheet 3). I am able to pull the first line of info with VLookup but need all rows for a specific date, which could range from zero to 10 rows depending on the day according to the date in cell G1 on Sheet 3. I am importing the needed information from Sheet 2 with vlookup, but since it is information from one cell to another its not an issue. Is there a way to transfer the needed data?

    Hello
    Here's another method to build a summary table, which calculates index of every row in source data matching given key and use the indices to retrieve rows of data.
    E.g.,
    Data (excerpt)
    A1  date
    A2  2015-03-12
    A3  2015-03-12
    A4  2015-03-12
    A5  2015-03-12
    B1  a
    B2  A
    B3  B
    B4  C
    B5  D
    C1  b
    C2  1
    C3  2
    C4  3
    C5  4
    Summary (excerpt)
    A1  a
    A2  =IF($D2<>"",INDEX(Data::B,$D2,1),"")
    A3  =IF($D3<>"",INDEX(Data::B,$D3,1),"")
    A4  =IF($D4<>"",INDEX(Data::B,$D4,1),"")
    A5  =IF($D5<>"",INDEX(Data::B,$D5,1),"")
    B1  b
    B2  =IF($D2<>"",INDEX(Data::C,$D2,1),"")
    B3  =IF($D3<>"",INDEX(Data::C,$D3,1),"")
    B4  =IF($D4<>"",INDEX(Data::C,$D4,1),"")
    B5  =IF($D5<>"",INDEX(Data::C,$D5,1),"")
    C1  2015-03-11
    C2 
    C3 
    C4 
    C5 
    D1  index
    D2  =IFERROR(MATCH(C$1,Data::A,0),"")
    D3  =IFERROR(MATCH(C$1,OFFSET(Data::A,D2,0,ROWS(Data::A)-D2,1),0)+D2,"")
    D4  =IFERROR(MATCH(C$1,OFFSET(Data::A,D3,0,ROWS(Data::A)-D3,1),0)+D3,"")
    D5  =IFERROR(MATCH(C$1,OFFSET(Data::A,D4,0,ROWS(Data::A)-D4,1),0)+D4,"")
    Notes.
    Formula in A2 and B2 can be filled down.
    Formula in D3 can be filled down. Note that D2 has different formula than D3.
    Tables are built in Numbers v2.
    Hope this may help you to get the basic idea.
    H

  • Clear all rows in a Bean Data Control

    I am using JDeveloper 11.1.1.6
    In my use case I have a screen that interacts with a Bean Data Control I have followed the steps in the following URL to create a Bean Data Control
    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_36/jdtut_11r2_36.html
    My screen successfully interacts with the Bean Data Control. This screen lives in a Bounded Task Flow (BTF). I can add rows using a Create Insert binding and can delete Rows as well. Once the user gets all rows into the Bean Data Control that they want inserted to a DB table, I can iterate through the Bean Data Control and post those records to the DB. It is possible for the users to add rows to the Bean Data Control and then link to a brand new screen which is in a different BTF which leaves rows in the Bean Data Control. Now the user goes back to the original screen. Upon returning, I want to empty (clear all rows) for the Bean Data Control so that they have a fresh start. Could you please provide guidance on what I might need to do to be able to clear a Bean Data Control when entering a BTF

    Hi,
    You can create a method to clear your Bean Data Control and call it with an invokeAction with property refresh="ifNeeded" and refreshCondition="#{pageFlowScope.isTimeToClearAll}", so pageFlowScope.isTimeToClearAll must be true only when you need to clear the BDC.
    Check this article: http://www.gebs.ro/blog/oracle/oracle-adf-invokeaction/
    AP

  • GROUP BY GROUPING SETS for a selected month and for year to date

    Below is a code example to demonstrate this question:
    declare @test table (ID int, Quantity int, Day date);
    insert into @test values
    (4, 500, '1/18/2014'),
    (4, 550, '1/28/2014'),
    (7, 600, '1/10/2014'),
    (7, 750, '1/11/2014'),
    (7, 800, '1/20/2014'),
    (1, 100, '1/2/2014'),
    (1, 125, '1/10/2014'),
    (8, 300, '1/7/2014'),
    (9, 200, '1/17/2014'),
    (9, 100, '1/22/2014'),
    (4, 900, '2/18/2014'),
    (4, 550, '2/28/2014'),
    (7, 600, '2/10/2014'),
    (7, 700, '2/11/2014'),
    (7, 800, '2/20/2014'),
    (1, 100, '2/2/2014'),
    (1, 150, '2/10/2014'),
    (8, 300, '2/7/2014'),
    (9, 200, '2/17/2014'),
    (9, 100, '2/22/2014'),
    (4, 500, '3/18/2014'),
    (4, 550, '3/28/2014'),
    (7, 600, '3/10/2014'),
    (7, 750, '3/11/2014'),
    (7, 800, '3/20/2014'),
    (1, 100, '3/2/2014'),
    (1, 325, '3/10/2014'),
    (8, 300, '3/7/2014'),
    (9, 200, '3/17/2014'),
    (9, 100, '3/22/2014'),
    (4, 500, '4/18/2014'),
    (4, 550, '4/28/2014'),
    (7, 100, '4/10/2014'),
    (7, 750, '4/11/2014'),
    (7, 800, '4/20/2014'),
    (1, 100, '4/2/2014'),
    (1, 325, '4/10/2014'),
    (8, 300, '4/7/2014'),
    (9, 200, '4/17/2014'),
    (9, 100, '4/22/2014'),
    (4, 500, '5/18/2014'),
    (4, 550, '5/28/2014'),
    (7, 600, '5/10/2014'),
    (7, 750, '5/11/2014'),
    (7, 50, '5/20/2014'),
    (1, 100, '5/2/2014'),
    (1, 325, '5/10/2014'),
    (8, 300, '5/7/2014'),
    (9, 200, '5/17/2014'),
    (9, 100, '5/22/2014');
    --detail
    select *
    from @test;
    --aggregation
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    go
    This is the aggregation query result:
    However, the desired result is to return only two rows: one row for month 3 and the other row for year to date (in the picture above YTD is the row that appears with {null} in the Month column).  Is there a way to achieve this goal by modifying the
    sample code above?  The requirement is to only read the data once (do not want a solution that involves a UNION which implies reading the data twice).

    you can add required filters in having clause. Here is the query -
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    having
    month(Day) = 3 or month(Day) is null;

  • Change field value in a table, based on another field value in the same row (for each added row)

    Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
    I am using this code :
    <HTML>
    <HEAD>
    <SCRIPT>
    function addRow(tableID) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for(var i=0; i<colCount; i++ ) {
    var newcell = row.insertCell(i);
    newcell.innerHTML = table.rows[1].cells[i].innerHTML;
    switch(newcell.childNodes[0].type) {
    case "text":
    newcell.childNodes[0].value = "";
    break;
    case "checkbox":
    newcell.childNodes[0].checked = false;
    break;
    case "select-one":
    newcell.childNodes[0].selectedIndex = 0;
    break;}}}
    function deleteRow(tableID) {
    try {var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    for(var i=0; i<rowCount; i++) {
    var row = table.rows[i];
    var chkbox = row.cells[0].childNodes[0];
    if(null != chkbox && true == chkbox.checked) {
    if(rowCount <= 2) {
    alert("Cannot delete all the rows.");
    break;}
    table.deleteRow(i);
    rowCount--;
    i--;}}}catch(e) {alert(e);}}
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
    <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
    <TABLE id="dataTable" width="350px" border="1">
    <TR>
    <TD width="32"></TD>
    <TD width="119" align="center"><strong>Activity</strong></TD>
    <TD width="177" align="center"><strong>Cost</strong></TD>
    </TR>
    <TR>
    <TD><INPUT type="checkbox" name="chk"/></TD>
    <TD>
    <select name="s1" id="s1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    </TD>
    <TD><input type="text" name="txt1" id="txt1"></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • Dynamic rows for dynamic data

    Hi,
    Can i have a JTable in which i create number of rows depending on the data i retreive frm the database, and also increase the number of rows on some kind of event.
    For example:
    I have to enter into a JTable names of students who are being admitted to a school, i have a specific format in the UI with fields(columns) like Name, Age, Sex. I give them a 5 rows as default. As the user comes to the 5th and 5th cell, tht is last cell of the table, as soon as the user presses Enter key another row/s should appear. And also if i am retreiving frm the database, depending on a query like give me names of students who are all females, then i dont know the number of rows required, therefore deciding dynamically or on-the-fly the number of rows required.
    Please if you can help me, tht will be great.
    Thank You.
    Ehsaan
    p.s-If u need more information pls do write.

    Here's an example of a model you may want to use. It allows you to add or subtract rows, as needed. It starts with 0 rows - in this case.
    You need to define another class TableRecord, which basically is contains the data to insert into a row.
    Hope this helps.
    public class FileModel extends AbstractTableModel
    public boolean isEditable = false;
    protected static int NUM_COLUMNS = 3;
    // initialize number of rows to start out with ...
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String first= "First";
    static final public String second= "Second";
    static final public String third= "Third";
    static final public String columnNames[] = {"FIrst", "Second", "Third"};
    // List of data
    protected Vector data = null;
    public FileModel()
    data = new Vector();
    public boolean isCellEditable(int rowIndex, int columnIndex)
    // The 3rd column or Value field is editable
    if(isEditable)
    if(columnIndex > 1)
    return true;
    return false;
    public Class getColumnClass(int c)
    return getValueAt(0, c).getClass();
    * Retrieves number of columns
    public synchronized int getColumnCount()
    return NUM_COLUMNS;
    * Get a column name
    public String getColumnName(int col)
    return columnNames[col];
    * Retrieves number of records
    public synchronized int getRowCount()
    if (numRows < START_NUM_ROWS)
    return START_NUM_ROWS;
    else
    return numRows;
    * Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int row, int column)
    try
    FileRecord p = (FileRecord)data.elementAt(row);
    switch (column)
    case 0:
    return (String)p.first;
    case 1:
    return (String)p.second;
    case 2:
    return (String)p.third;
    catch (Exception e)
    return "";
    public void setValueAt(Object aValue, int row, int column)
    FileRecord arow = (FileRecord)data.elementAt(row);
    arow.setElementAt((String)aValue, column);
    fireTableCellUpdated(row, column);
    * Returns information of an entire record at location row
    public synchronized FileRecord getRecordAt(int row) throws Exception
    try
    return (FileRecord)data.elementAt(row);
    catch (Exception e)
    throw new Exception("Record not found");
    * Used to add or update a record
    * @param tableRecord
    public synchronized void updateRecord(FileRecord tableRecord)
    String file = tableRecord.file;
    FileRecord p = null;
    int index = -1;
    boolean found = false;
    boolean addedRow = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    { //update
    data.setElementAt(tableRecord, index);
    else
    if (numRows <= nextEmptyRow)
    //add a row
    numRows++;
    addedRow = true;
    index = nextEmptyRow;
    data.addElement(tableRecord);
    //Notify listeners that the data changed.
    if (addedRow)
    nextEmptyRow++;
    fireTableRowsInserted(index, index);
    else
    fireTableRowsUpdated(index, index);
    * Used to delete a record
    public synchronized void deleteRecord(String file)
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    data.removeElementAt(i);
    nextEmptyRow--;
    numRows--;
    fireTableRowsDeleted(START_NUM_ROWS, numRows);
    }

Maybe you are looking for