当通过 Struts 填充表时,如何实现 HTML 表排序
How do I implement HTML table sorting when table is populated via Struts
我有一个HTML表,其中元素通过struts(<s:iterator>
标签)填充。代码片段如下所示。
<table cellspacing="0" border="0" width="100%" class="select_table margin-top10" id="example_table">
<thead>
<tr class="oddRows">
<th width="300px" align="left">Column A</th>
<th width="150px" align="left">Column B</th>
<th width="120px"align="left">Column C</th>
<th align="left">Action</th>
</tr>
</thead>
</table>
<div style="height:200px;" class="data_holder">
<table class="select_table" cellspacing="0" cellpadding="0" border="0" style="width: 670px;">
<tbody>
<s:iterator value="exampleList" status="searchResultStatus">
<tr id="exampleRow-<s:property value="#searchResultStatus.index"/>" <s:if test="#searchResultStatus.even">class="oddRows"</s:if> >
<td id="sName<s:property value="#searchResultStatus.index"/>" width="295px"><span id="scheduleName<s:property value="#searchResultStatus.index"/>" class="ellipsis35" title="<s:property value="exampleName"/>"><s:property value="exampleName"/></span></td>
<td id="sType<s:property value="#searchResultStatus.index"/>" width="150px"><span id="sType<s:property value="#searchResultStatus.index"/>"><s:property value="exampleType" /></span></td>
<td id="sLevel<s:property value="#searchResultStatus.index"/>"><span id="sLevel<s:property value="#searchResultStatus.index"/>"><s:property value="exampleLevel" /></span></td>
<td width="10%"><div title="Click to select" id="select-contact-<s:property value="#searchResultStatus.index"/>" ><img id="select-contact-<s:property value="#searchResultStatus.index"/>" src="../images/popup-select.gif"></div></td>
</tr>
</s:iterator>
</tbody>
</table>
如何在此表上实现排序?请帮忙!
你可以使用 struts2 s:sort 标签来做到这一点。
<s:sort comparator="your.impl.of.comparator" source="exampleList">
<s:iterator status="searchResultStatus">
<tr id="exampleRow-<s:property value="#searchResultStatus.index"/>" <s:if test="#searchResultStatus.even">class="oddRows"</s:if> >
<td id="sName<s:property value="#searchResultStatus.index"/>" width="295px"><span id="scheduleName<s:property value="#searchResultStatus.index"/>" class="ellipsis35" title="<s:property value="exampleName"/>"><s:property value="exampleName"/></span></td>
<td id="sType<s:property value="#searchResultStatus.index"/>" width="150px"><span id="sType<s:property value="#searchResultStatus.index"/>"><s:property value="exampleType" /></span></td>
<td id="sLevel<s:property value="#searchResultStatus.index"/>"><span id="sLevel<s:property value="#searchResultStatus.index"/>"><s:property value="exampleLevel" /></span></td>
<td width="10%"><div title="Click to select" id="select-contact-<s:property value="#searchResultStatus.index"/>" ><img id="select-contact-<s:property value="#searchResultStatus.index"/>" src="../images/popup-select.gif"></div></td>
</tr>
</s:iterator>
</s:sort>
其中 your.impl.of.comparator 是 java.util.Comparator 的实现
相关文章:
- 如何在javascript中实现映射或排序集
- 堆排序实现进行了太多比较
- 使用可排序项实现轮班点击
- 用Javascript实现了带有合并排序算法的反转计数
- JavaScript的原生排序函数是如何实现的
- Go 中的快速排序实现
- 当通过 Struts 填充表时,如何实现 HTML 表排序
- 在 Javascript 中实现合并排序
- jqGrid使用JsonString JsonReader实现服务器端排序分页过滤
- React.js-实现组件排序
- 如何在metro.js中实现图像重新排序
- Javascript快速排序算法实现
- 如何在Yii中实现表行拖放排序
- 在javascript中合并排序的简单实现
- 需要帮助实现jquery指令的排序
- js比较器函数,如何实现降序排序
- 实现html表的数值排序
- 如何实现一个排序,但随机列表与javascript/jquery
- 为什么这个(部分)归并排序实现会破坏堆栈?
- 在javascript中实现搜索结果的多字段排序