Results 1 to 2 of 2
  1. #1
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    37
    Rep Power
    0

    Default Show group header above each displayed table

    Dear team,



    I need your assistant and help in solving the issue while displaying the records in a table. I am looking for a group header to be placed above each printed table for its related category and subcategory, as well as, the no. of the records for each table to be shown at the top of the table.

    The table contains columns for category, subcategory, name. ex:

    Category Subcategory Name

    CON Retail AAA

    CON Wholesale BBB

    SPEC Retail CCC



    What I am looking for is the below layout:



    Category/Subcategory (No. of records) –similar to a group header


    Name – Country ..etc ----Table header

    table records



    Here is my code below:
    Java Code:
     
    
    <%
    
     
    
    //Retrieve the values from the DB
    
     
    
    while (rs.next())
    
                                    {
    
                                    category_name1=rs.getString("category_name");
    
                                   subcategory_name1=rs.getString("subcategory_name");
    
     
    
    //to compare the existing category with the previous one and to display group header
    
    if ((category_name1).equals(temp_category_name) )
    
                                                    {
    
                                                    category_name1="";
    
    %>
    
     
    
    <%=category_name1%> / <%=subcategory_name1%> <%=count%>  //Currently it is showing duplicate values many times and the count is wrong
    
    <%
    
    }
    
                         
    
                                    if (!(subcategory_name1).equals(temp_subcategory_name) )
    
                                                    {
    
                                                   
    
                                                    count=0;
    
     
    
    %>
    
                   
    
                   
    
    <table width="80%">
    
     
    
                    <thead>
    
                                    <tr>
    
                                                    <th>No.</th>
    
                                                    <th> Name</th>
    
                                                    <th>Country </th>
    
     
    
                                    </tr>
    
                    </thead>
    
    <%
    
    }
    
    %>
    
                                    <tbody>
    
    <%
    
                                                   
    
     
    
                                                   name=rs.getString("name");
    
                                                    country_name=rs.getString("country_name");
    
                                                   temp_category_name=category_name1;
    
                                                   temp_subcategory_name=subcategory_name1;
    
    count++;
    
    %>
    
    <tr>
    
                                                    <td><%=i%></td>
    
                                                    <td><%=institution_name%></td>
    
                                                    <td><%=country_name%></td>                                            
    
                                    </tr>
    
     
    
    <%
    
                                                                   
    
                    }
    
     
    
       
    
    %>
    
     
    
                    </tbody>
    
    </table>
    The problem in the above code is that it is showing the group headers category & sub ctageory multiple times and the count is incorrect. So, please assist me in correcting the above one.

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    11

    Default Re: Show group header above each displayed table

    The problem is you did not fectch data in ordered format of category and sub category. You can alter your query like "order by category , sub ctageory" so that you may not get too many headers. I hope it would also resolve your count problem as well.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Groupable table header - not able to sort
    By new2java2009 in forum New To Java
    Replies: 2
    Last Post: 07-08-2011, 09:49 PM
  2. Best way to model table with header characters?
    By doa24uk in forum New To Java
    Replies: 1
    Last Post: 07-01-2011, 01:44 PM
  3. How to change the height of a table header?
    By Zelord in forum AWT / Swing
    Replies: 2
    Last Post: 12-20-2010, 08:08 PM
  4. DisplayTag Table header styling problem and paging
    By selvi in forum Web Frameworks
    Replies: 0
    Last Post: 08-05-2010, 08:14 AM
  5. Updating Displayed Table Rows
    By raycini in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 04-20-2009, 08:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •