<rich:extendedDataTable>
真的不能很好地处理水平滚动。事实上,开发人员似乎着手让水平滚动几乎不可能。
您可以在启用水平滚动的情况下放入<rich:extendedDataTable>
a <div>
,但如果您将其保留在那里,它将不起作用。( )中的嵌套<div>
s 之一是绝对定位的,将其从文档流中移除。<rich:extendedDataTable>
div.extdt-innerdiv
作为参考,这是 的基本输出结构<rich:extendedDataTable>
,假设三个<rich:column>
元素的宽度为 100px 和两条记录:
<div id="form_id:edt_id" class="extdt-maindiv rich-extdt-maindiv">
<div id="form_id:edt_id:od" class="extdt-outerdiv">
<div id="form_id:edt_id:innerd" class="extdt-innerdiv">
<table id="form_id:edt_id:tu" class="extdt-table-layout">
<colgroup id="form_id:edt_id:colgroup:header">
<col width="100" />
<col width="100" />
<col width="100" />
</colgroup>
<thead id="form_id:edt_id:header" class="extdt-thead">
<tr class="extdt-subheader rich-extdt-subheader">
<th id="form_id:edt_id:column_1_id" class="extdt-menucell extdt-subheadercell rich-extdt-subheadercell">Column Header 1</th>
<th id="form_id:edt_id:column_2_id" class="extdt-menucell extdt-subheadercell rich-extdt-subheadercell">Column Header 2</th>
<th id="form_id:edt_id:column_3_id" class="extdt-menucell extdt-subheadercell rich-extdt-subheadercell">Column Header 3</th>
</tr>
<tr class="extdt-table-filterrow rich-extdt-subheader"> <!-- only if filtering is enabled -->
<th class="extdt-subheadercell rich-extdt-subheadercell"><!-- omitted for example purposes --></th>
<th class="extdt-subheadercell rich-extdt-subheadercell"><!-- omitted for example purposes --></th>
<th class="extdt-subheadercell rich-extdt-subheadercell"><!-- omitted for example purposes --></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">
<div id="form_id:edt_id:sd" class="extdt-content">
<table id="form_id:edt_id:n" class="extdt-table-layout">
<colgroup id="form_id:edt_id:colgroup:body">
<col width="100" />
<col width="100" />
<col width="100" />
</colgroup>
<tbody id="form_id:edt_id:tb">
<tr id="form_id:edt_id:n:0" class="extdt-firstrow rich-extdt-firstrow">
<td id="form_id:edt_id:0:column_1_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 1, Row 1</div>
</td>
<td id="form_id:edt_id:0:column_2_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 2, Row 1</div>
</td>
<td id="form_id:edt_id:0:column_3_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 3, Row 1</div>
</td>
</tr>
<tr id="form_id:edt_id:n:1" class="extdt-firstrow rich-extdt-firstrow">
<td id="form_id:edt_id:1:column_1_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 1, Row 2</div>
</td>
<td id="form_id:edt_id:1:column_2_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 2, Row 2</div>
</td>
<td id="form_id:edt_id:1:column_3_id" class="extdt-cell rich-extdt-cell">
<div class="extdt-cell-div">Column 3, Row 2</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
<tfoot id="form_id:edt_id:footer">
<tr class="extdt-footer rich-extdt-footer">
<td class="extdt-footercell rich-extdt-footercell" scope="colgroup" colspan="3">
<!-- table footer goes here if defined -->
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<div id="form_id:edt_id:column_1_idmenu">
<script type="text/javascript">
// context menu script snipped for example purposes
</script>
</div>
<div id="form_id:edt_id:column_2_idmenu">
<script type="text/javascript">
// context menu script snipped for example purposes
</script>
</div>
<div id="form_id:edt_id:column_3_idmenu">
<script type="text/javascript">
// context menu script snipped for example purposes
</script>
</div>
</div>
您可以将水平滚动添加到div.extdt-innerdiv
,但<rich:extendedDataTable>
的列自动调整大小功能 ( ExtendedDataTable.DataTable_formId_edtId.calculateWidthsFromRatios()
) 基本上会被此混淆,将所有从组件开始的列maxWidth
(从 的初始宽度派生div.extdt-maindiv
)调整为 20px 宽。
我试过了...
<rich:extendedDataTable>
用元素包装<div>
并设置以下内容:
position: relative;
width: 100%;
overflow-x: auto;
- 所需的高度,否则由于下一个要点,您只会看到滚动条。
- 绝对
div.extdt-maindiv
定位
- 提供静态定位
div.extdt-outerdiv
和div.extdt-innerdiv
自动宽度
...但这似乎没有任何效果。
我认为这可能是因为我在 Firebug 中进行了大部分更改,并且mainDiv.getWidth()
(from calculateWidthsFromRatios()
) 正在检索缓存值,mainDiv.element.boxWidth
. 这个值是在ClientUI.common.box.Box.setWidth()
(common-scrollable-data-table.js) 中设置的,它只被调用一次;<rich:extendedDataTable>
如果我调整浏览器窗口的大小(在我的情况下为 100% 宽度),它不会再次被调用。
我将尝试在我的 CSS 文件中进行这些更改,看看是否一切都神奇地起作用。但是,JavaScript for<rich:extendedDataTable>
非常复杂,并且没有记录在案,所以我可能在某处遗漏了一些东西。我会跟进我的结果。
编辑:在我的 CSS 中进行更改后,我仍然遇到了列缩短问题。
因此,为了避免创建包装 div,我将水平滚动添加到div.extdt-innerdiv
:
.extdt-innerdiv { overflow-y: hidden; overflow-x: auto !important; }
然后,在页脚中<rich:extendedDataTable>
,我禁用了该calculateWidthsFromRatios()
功能:
<rich:extendedDataTable id="edtId">
<!-- rest of extended data table -->
<f:facet name="footer">
<script type="text/javascript">
jQuery(function() {
// Disable ratio-based column resizing.
ExtendedDataTable.DataTable_formId_edtId.calculateWidthsFromRatios = function() {};
});
</script>
</f:facet>
</rich:extendedDataTable>
我使用表格的页脚来强制每次重新渲染组件时执行此 JavaScript。
即使使用此解决方案,用户也无法手动扩展列的宽度,因为 extended-data-table.js 中的 JavaScript 会阻止将列调整为比mainDiv.element.boxWidth
. 为了能够像这样调整大小,最好只向 JBoss 提交一个补丁来修复<rich:extendedDataTable>
,因为目前没有计划在 RichFaces 3.X 中修改其行为(根据JBoss 社区 JIRA 中的#RF-4871)。
祝你好运。