Rich Extended DataTable列宽

时间:2009-11-08 14:45:30

标签: jsf richfaces

我遇到了RichFaces扩展数据表

的问题

如果列多说20,而不是给出水平滚动条,则列会被压缩。

我尝试以%为单位给出列宽,px。但没有用。

有谁熟悉这个?

<rich:column label="Select" sortable="false" width="10%">
  <f:facet name="header"> 
    <h:selectBooleanCheckbox id="chk" align="center"
      value="#{bean.selectAll}" onclick="selectAll();"/>
  </f:facet>
  <input id="part_#{rowKey}" type="checkbox"
    name="selectedParts" value="#{listVar.id}" />
</rich:column>

5 个答案:

答案 0 :(得分:12)

<rich:extendedDataTable>确实无法很好地处理水平滚动。事实上,似乎开发人员开始着手进行水平滚动。

您可以将<rich:extendedDataTable>放入<div>并启用水平滚动,但如果您将其保留,则无效。 <div><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())基本上会被此混淆,调整所有通过组件{{ {1}}(从maxWidth的初始宽度导出)到20px宽。

我试过......

  • 使用div.extdt-maindiv元素包装<rich:extendedDataTable>并设置以下内容:
    • <div>
    • position: relative;
    • width: 100%;
    • 所需的高度,否则您只会看到下一个项目符号点的滚动条。
  • 使overflow-x: auto;绝对定位
  • 同时给予div.extdt-maindivdiv.extdt-outerdiv静态定位和自动宽度

......但这似乎没有任何效果。

我想这可能是因为我在Firebug中进行了大部分更改,而div.extdt-innerdiv(来自mainDiv.getWidth())正在检索缓存值{{1} }。该值在calculateWidthsFromRatios()(common-scrollable-data-table.js)中设置,并且只调用一次;如果我调整浏览器窗口大小,则不会再次调用它(在我的情况下mainDiv.element.boxWidth的宽度为100%)。

我会尝试在我的CSS文件中进行这些更改,看看是否所有内容都神奇地起作用。 ClientUI.common.box.Box.setWidth()的JavaScript非常复杂,而且没有记录,所以我可能会遗漏某些地方的东西。我会跟进我的结果。


编辑:在我的CSS中进行更改后,我仍然遇到了缩短列的问题。

因此,为了避免创建包装器div,我将水平滚动添加到<rich:extendedDataTable>

<rich:extendedDataTable>

然后,在div.extdt-innerdiv的页脚中,我禁用了.extdt-innerdiv { overflow-y: hidden; overflow-x: auto !important; } 函数:

<rich:extendedDataTable>

我使用了表格的页脚,以便每次重新生成组件时强制执行此JavaScript。

即使使用此解决方案,用户也无法手动扩展列的宽度,因为extended-data-table.js中的JavaScript会阻止列的调整大小超过calculateWidthsFromRatios()。为了能够像这样调整大小,人们可能只需向JBoss提交修补程序来修复<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> ,因为目前没有计划在RichFaces 3.X中修改其行为(根据#RF-4871) JBoss社区JIRA)。

祝你好运。

答案 1 :(得分:5)

您应指定宽度而不是“px”或“%”,例如

<rich:column label="Select" sortable="false" width="100">

扩展数据表的issues具有水平滚动功能,但您可以指定固定的表格宽度(以像素为单位),并将表格放在div中,并设置overflow-x进行滚动。

答案 2 :(得分:3)

我结合了各种各样的想法并提出了以下建议:

如上所述 - 有待修复的事情。一个是超出表宽度100%的可滚动性,第二个是滚动条本身。所以我将有一些js文件来修复调整大小问题和一些css来添加滚动条......

page.xhtml - 你的页面里面有一些extended-dt。

<head>
    <a4j:loadStyle
        src="resource:///org/company/project/css/ExtendedDatatableFix.css"
        media="screen" />
    <a4j:loadScript
        src="resource:///org/company/project/js/ExtendedDataTableHeaderFixScrollable.js" />
</head>
<body>
    <!-- prevent IE to come up with ExtendedDataTable-bla not defined-js-error -->
    <rich:extendedDataTable id="dummy_table_for_extended_datatable_fix" rendered="false">
    </rich:extendedDataTable>


    <rich:extendedDataTable id="here_goes_your_datatable">
        <!-- your ext-dt -->
    </rich:extendedDataTable>
</body>

ExtendedDatatableFix.css - 不是那么准确,但嘿 - 改进的空间

.extdt-maindiv {
    margin-bottom: 17px;
}
.extdt-outerdiv {
    overflow-x:auto !important;
    overflow-y:hidden;
    height: 108% !important;
}
.extdt-innerdiv {
    height: 100% !important;
}
.extdt-content{
    overflow-x:hidden;
    overflow-y:scroll;
}

ExtendedDataTableHeaderFixScrollable.js - 从这里复制: http://community.jboss.org/thread/146108

 ExtendedDataTable.DataTable.header.prototype.OnSepMouseMove = function(event) {
      if(this.dragColumnInfo && this.dragColumnInfo.mouseDown) {
           if(!this.dragColumnInfo.dragStarted) {
                this.dragColumnInfo.dragStarted = true;
                this._showSplitter(this.dragColumnInfo.srcElement.columnIndex);
           }
           var delta = Event.pointerX(event) - 
                this.dragColumnInfo.startX
           if (delta < this.minDelta) {
                delta = this.minDelta;
           }
           /*if (delta > this.maxDelta) {
                delta = this.maxDelta;
           }*/
           var x = this.dragColumnInfo.originalX + delta;
           var finalX = x - this.minColumnWidth - 6 //6 stands for sep span width;
           this.columnSplitter.moveToX(finalX);                     
           Event.stop(event);
      }
 }

 ExtendedDataTable.DataTable.header.prototype.OnSepMouseUp = function(event) {
      Event.stop(event);
      Event.stopObserving(document, 'mousemove', this.eventSepMouseMove);
      Event.stopObserving(document, 'mouseup', this.eventSepMouseUp);
      if(this.dragColumnInfo && this.dragColumnInfo.dragStarted) {
           this.dragColumnInfo.dragStarted = false;
           this.dragColumnInfo.mouseDown = false;

           var delta = Event.pointerX(event) - 
                this.dragColumnInfo.startX;
           if (delta < this.minDelta) {
                delta = this.minDelta;
           }
           /*if (delta > this.maxDelta) {
                delta = this.maxDelta;
           }*/
           var columnIndex = this.dragColumnInfo.srcElement.columnIndex;
           var newWidth = this.getColumnWidth(columnIndex) + delta;

           this.extDt.setColumnWidth(columnIndex, newWidth);
           this.setColumnWidth(columnIndex,newWidth);
           this.extDt.updateLayout();
           if (this.extDt.onColumnResize){
                //set properly value to this.columnWidths
                this.extDt.columnWidths = "";
                for (i=0; i<this.columnsNumber; i++){
                     this.extDt.columnWidths += "" + this.getColumnWidth(i) + ";";
                }//for
                this.extDt.onColumnResize(event, this.extDt.columnWidths);
           }
      }
      this._hideSplitter();
 }

ExtendedDataTable.DataTable.prototype.calculateWidthsFromRatios = function() {
    LOG.debug('firing calculateWidthsFromRatios');
    var c = this.getColumns();
    var scrollbarWidth = this.getScrollbarWidth();
    this._scrollbarWidth = scrollbarWidth;
    LOG.debug('Scrollbar: ' + scrollbarWidth);
    var mainDivWidth = this.mainDiv.getWidth();
    LOG.debug('Main DIV: ' + mainDivWidth);
    var maxWidth = mainDivWidth - scrollbarWidth;
    LOG.debug('Width to spread: ' + maxWidth);
    var totalWidth = 0;
    for (i = 0; i < c.length - 1; i++) {
        LOG.debug('Column[' + i + '] ratio: ' + this.ratios[i]);
        var w = Math.round(this.ratios[i] * maxWidth);
        if (w < parseInt(this.minColumnWidth)) {
            w = parseInt(this.minColumnWidth);
        }
        LOG.debug('setting column ' + i + ' to width: ' + w);
        this.setColumnWidth(i, w);
        this.header.setColumnWidth(i, w);
        totalWidth += w;
    }
    /*
     * if (totalWidth > maxWidth) {
     * c[c.length - 2].width -= (totalWidth - maxWidth);
     * }
     */
};

答案 3 :(得分:0)

要启用水平滚动条,请参阅此处的解决方法https://jira.jboss.org/jira/browse/RF-4871

要在显示水平滚动条时使列可调整大小,请参阅此http://community.jboss.org/message/518878#518878

答案 4 :(得分:0)

根据这个例子:

RichFaces Showcase

宽度以这种方式使用(检查xhtml的来源):

<rich:column filter="#{carsFilteringBean.mileageFilterImpl}" width="150px"

对我而言,它没有问题。

问候。