昨天公司需求需要实现一个动态列功能,于是研究了一下DisplayTag是否能支持动态列。答案是实现起来也比较简单的。只需要将column用logic:iterate来循环使用就行了:
<%
ArrayListarrList
=
new
ArrayList();
HashMaprowMap
=
new
HashMap();
rowMap.put(
"
dunPersonel
"
,
"
xxx
"
);
rowMap.put(
"
taskPackageNumber
"
,
"
xxx
"
);

ArrayListcolList
=
new
ArrayList();
colList.add(
"
1
"
);
colList.add(
"
2
"
);
colList.add(
"
3
"
);
rowMap.put(
"
titlenum
"
,colList);
rowMap.put(
"
data1
"
,
"
23432
"
);
rowMap.put(
"
data2
"
,
"
35221
"
);
rowMap.put(
"
data3
"
,
"
52.23
"
);

arrList.add(rowMap);
request.setAttribute(
"
result
"
,arrList);
%>
<
display:tableuid
=
"
arow
"
name
=
"
result
"
export
=
"
false
"
pagesize
=
"
10
"
class
=
"
paging_table
"
requestURI
=
"
/creditcarddun/reclaimRatioStatistics.do
"
>
<
display:setPropertyname
=
"
basic.empty.showtable
"
value
=
"
true
"
/>

<
display:caption
>
<
bean:messagekey
=
"
caption.cardAccountQuery.cardAccountStatusList
"
/>
</
display:caption
>

<
display:columntitleKey
=
"
label.reclaimRatioStatistics.dunPersonel
"
property
=
"
dunPersonel
"
style
=
"
width:20%;
"
sortable
=
"
true
"
/>
<
display:columntitleKey
=
"
label.reclaimRatioStatistics.taskPackageNumber
"
property
=
"
taskPackageNumber
"
style
=
"
width:20%;
"
sortable
=
"
true
"
/>

<
logic:iterateid
=
"
num
"
name
=
"
arow
"
property
=
"
titlenum
"
>
<
display:columntitleKey
=
"
label.reclaimRatioStatistics.reclaimRatio
"
property
=
"
data${num}
"
style
=
"
width:10%
"
>
</
display:column
>
</
logic:iterate
>
<%--<
display:columntitleKey
=
"
label.reclaimRatioStatistics.reclaimRatio
"
property
=
"
reclaimRatio
"
style
=
"
width:10%
"
sortable
=
"
true
"
/>
--%>
</
display:table
>
<%
ArrayListarrList
=
new
ArrayList();
HashMaprowMap
=
new
HashMap();
rowMap.put(
"
dunPersonel
"
,
"
xxx
"
);
rowMap.put(
"
taskPackageNumber
"
,
"
xxx
"
);
ArrayListcolList
=
new
ArrayList();
colList.add(
"
1
"
);
colList.add(
"
2
"
);
colList.add(
"
3
"
);
rowMap.put(
"
titlenum
"
,colList);
rowMap.put(
"
data1
"
,
"
23432
"
);
rowMap.put(
"
data2
"
,
"
35221
"
);
rowMap.put(
"
data3
"
,
"
52.23
"
);
arrList.add(rowMap);
request.setAttribute(
"
result
"
,arrList);
%>
<
display:tableuid
=
"
arow
"
name
=
"
result
"
export
=
"
false
"
pagesize
=
"
10
"
class
=
"
paging_table
"
requestURI
=
"
/creditcarddun/reclaimRatioStatistics.do
"
>
<
display:setPropertyname
=
"
basic.empty.showtable
"
value
=
"
true
"
/>

<
display:caption
>
<
bean:messagekey
=
"
caption.cardAccountQuery.cardAccountStatusList
"
/>
</
display:caption
>

<
display:columntitleKey
=
"
label.reclaimRatioStatistics.dunPersonel
"
property
=
"
dunPersonel
"
style
=
"
width:20%;
"
sortable
=
"
true
"
/>
<
display:columntitleKey
=
"
label.reclaimRatioStatistics.taskPackageNumber
"
property
=
"
taskPackageNumber
"
style
=
"
width:20%;
"
sortable
=
"
true
"
/>

<
logic:iterateid
=
"
num
"
name
=
"
arow
"
property
=
"
titlenum
"
>
<
display:columntitleKey
=
"
label.reclaimRatioStatistics.reclaimRatio
"
property
=
"
data${num}
"
style
=
"
width:10%
"
>
</
display:column
>
</
logic:iterate
>
<%--<
display:columntitleKey
=
"
label.reclaimRatioStatistics.reclaimRatio
"
property
=
"
reclaimRatio
"
style
=
"
width:10%
"
sortable
=
"
true
"
/>
--%>
</
display:table
>
本文介绍如何使用DisplayTag实现表格的动态列功能。通过逻辑迭代循环遍历列名并设置属性,可以灵活调整显示的列数及内容。适用于需要动态展示不同列数的场景。

134

被折叠的 条评论
为什么被折叠?



