Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group column headers using the Display tag Java library?

I am using the Display tag Java library in my web application. I need to group some column headers ("General" and "Office Info") as shown in the following example.

enter image description here

like image 496
ashishjmeshram Avatar asked May 12 '12 10:05

ashishjmeshram


1 Answers

Ashish, I tried to clarify your question and have hopefully got it right.

If you check the HTML source generated by DisplayTag it puts the column headings into a <thead> tag like this

<table cellspacing="0" cellpadding="0">
<thead>
    <tr>
        <th class="dtsortable">
            <a href="...">Firstname</a>
        </th>
        <th class="dtsortable">
            <a href="...">Lastname</a>
        </th>
    </tr>
</thead>
<tbody>
...

So what you want to achieve is inserting a new row into the for your groupings. I would suggest that the easiest way to achieve this is not to mess with DisplayTag code and use JQuery to manipulate the DOM to do this.

Using JQuery

To get this HTML code...

<table id="display-tag "cellspacing="0" cellpadding="0">
<thead>
    <tr>
        <th colspan="2">
            heading
        </th>
    </tr>
    <tr>
        <th class="dtsortable">
            <a href="...">Firstname</a>
        </th>
        <th class="dtsortable">
            <a href="...">Lastname</a>
        </th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Bob</td>
        <td>Test</td>
    </tr>
    <tr>
        <td>Jane</td>
        <td>Test</td>
    </tr>
</tbody>
</table>

You can use this JQuery code...

$('#display-tag > thead').prepend('<tr><th colspan="2">heading</th></tr>');

You can see this in action with this JSFiddle

like image 151
Brad Avatar answered Oct 25 '22 09:10

Brad