I am new to do this sorting technique in jsp page of dynamic content. My application is integrated with struts2+jsp+hibenate. I am using the following code in jsp.
report.jsp
<table class="report_view_table" id="results">
<thead>
<tr> <th width="35" scope="col" abbr="no">No
</td>
<th width="50" scope="col" abbr="status">Date
</td>
<th width="80" scope="col" abbr="option">productName
</td>
</tr>
</thead>
<tbody>
<s:if test="resultList.size() > 0">
<s:if test="productName.size() > 0">
<s:iterator status="rowNo" value="resultList">
<s:set name="Result_product" value="%{productId}" />
<tr> <td><span class="check"><s:property value="%{#rowNo.count}" /></span></td>
<td><span class="check"><s:property value="%{proDate}" /></span></td>
<td><span class="check"><s:iterator value="productName">
<s:set name="product"value="%{productId}" />
<s:if test="%{#product== #Result_product}">
<s:property value="%{productionName}" /> </s:if></s:iterator>
</span></td>
</tr>
</s:iterator>
</s:if>
</s:if>
<s:else>No report is available
</s:else>
<s:else>No report is available
</s:else>
</tbody>
</table>
Here, i want to sort the table by its column heading. how to sort this dynamic content of table. Anybody please help me to do this functionality. Thanks in advance.
Client side sorting : use jquery dataTable
for using jquery datatable specify the id of you table to the jquery datatable.
e.g. results is the id of your table
add javascript file for the jquery and jquery datatable
Server Side sorting : sort you list resultList on server side using Arrays.sort() by help of interface Comparable refer http://docs.oracle.com/javase/tutorial/collections/interfaces/order.html