【问题标题】:Need to control width of the table column in print打印时需要控制表格列的宽度
【发布时间】:2020-02-11 21:39:11
【问题描述】:

我在我的 Visualforce 页面中使用 Bootstrap,生成 Vf 页面时表格看起来还不错。

我需要使用 ctrl+P 打印此内容,但是当其中一个列值(名称)太大时,表格在打印时会被截断。

所以我添加了表格固定布局和自动换行。

现在它工作正常,但是现在所有列的宽度相同,序列号和名称的宽度相同,这看起来很尴尬。

链接中的表格图片

Table

<div class="row" style="padding-bottom:20px;">
    <div class="col-md-12">
        <table class="table table-sm table-bordered">
            <thead>
                <tr style="background-color:#00205b">
                    <th style="color:#ffffff;border-bottom-color:#bf0d3e;" rowspan="2">#</th>
                    <th style="color:#ffffff;border-bottom-color:#bf0d3e;" rowspan="2">Employee/Dependent</th>
                    <th style="color:#ffffff;border-bottom-color:#bf0d3e;" rowspan="2">Relationship</th>
                    <apex:repeat value="{!planMetadataMap }" var="planName">
                        <th style="color:#ffffff;text-align:center;" colspan="2" rowspan="1">{!planName}</th>
                    </apex:repeat>
                </tr>
                <tr style="background-color:#00205b">
                    <apex:repeat value="{!planMetadataMap}" var="planMeta">
                        <apex:repeat value="{!planMetadataMap[planMeta]}" var="planMetavalue">
                            <th style="color:#ffffff;border-bottom-color:#bf0d3e;" rowspan="1">{!planMetavalue}</th>
                        </apex:repeat>
                    </apex:repeat>
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!qliWrapperMainList}" var="qliWrapperlist">
                    <apex:repeat value="{!qliWrapperlist}" var="qliWrapper">
                        <tr style="background-color:#fafafa">
                            <td>{!qliWrapper.seq_number}</td>
                            <apex:outputPanel rendered="{!(qliWrapper.relation==null)}">
                                <td>{!qliWrapper.Name}</td>
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!(qliWrapper.relation!=null)}">
                                <td style="padding-left:20px;">-&nbsp;{!qliWrapper.Name}</td>
                            </apex:outputPanel>
                            <td>{!qliWrapper.relation}</td>
                            <apex:repeat value="{!planMetadataMap}" var="planMain">
                                <apex:repeat value="{!planMetadataMap[planMain]}" var="mapSubPlan">
                                    <td>${!qliWrapper.planMap[planMetadataMap[planMain][mapSubPlan]]}</td>
                                </apex:repeat>
                                </apex:repeat>
                        </tr>
                    </apex:repeat>
                    <tr>
                        <td style="border-bottom-color:#533278;"></td>
                        <td style="border-bottom-color:#533278;"></td>
                        <td style="border-bottom-color:#533278;text-align:right">Family Total</td>
                        <apex:repeat value="{!planMetadataMap}" var="planMain">
                            <apex:repeat value="{!planMetadataMap[planMain]}" var="mapSubPlan">
                                <td style="border-bottom-color:#533278;text-align:right">${!qliWrapperlist[0].planTotal[planMetadataMap[planMain][mapSubPlan]]}</td>
                            </apex:repeat>
                        </apex:repeat>
                    </tr>
                </apex:repeat>
            </tbody>
        </table>
    </div>

为打印添加的代码:-

<style>
@media print {
.table th { word-wrap: break-word;  background-color: #eeeeee 
   !important; color: #333333 !important; }
          .table td { word-wrap: break-word;  background- 
          color: #ffffff !important; color: #333333 
        !important; }
.table { table-layout: fixed !important; }
 }
</style>

【问题讨论】:

    标签: html twitter-bootstrap printing html-table


    【解决方案1】:

    如果你愿意,你可以将任何 td 的 with 设置为 XYZ。 然后单词会中断,并且表格适合打印页边距。

    例如:

    <style>
    @media print {
        .table th { 
            word-wrap: break-word;  
            background-color: #eeeeee !important;
            color: #333333 !important; 
        }
        .table td {
            max-width:10%;
            background-color: #ffffff !important;
            color: #333333 !important; 
        }
        .table { 
            table-layout: fixed !important; 
        }
    }
    </style>
    

    【讨论】:

    • 我试过这段代码,但所有列的宽度仍然相同。您是否建议在第一个序列号列中添加特定宽度,该怎么做?
    • 是的,如果你为每列设置一个类,你可以设置每列的宽度;)
    猜你喜欢
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 2019-05-20
    • 2023-03-18
    • 2015-12-30
    • 2010-10-10
    • 1970-01-01
    相关资源
    最近更新 更多