【问题标题】:datatables - make the th header cells wrap the words数据表 - 使第 th 标题单元格包含单词
【发布时间】:2016-04-15 01:25:09
【问题描述】:

我正在使用数据表,想知道是否可以选择让标题换行。

我使用紧凑型显示器

问题是,一些 javascript 将表格标题单元格的宽度设置为固定的像素数。

所以我想要:

fees
covered

name
shown


amount
shown

在标题中

编辑:添加<br/> 标签的问题是列的宽度保持完全相同,但我希望它们变得更小、更窄,请参见此处:

【问题讨论】:

    标签: datatables


    【解决方案1】:

    在表头使用换行符<br>

    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>fees<br>covered</th>
                <th>name<br>shown</th>
                <th>amount<br>shown</th>
            </tr>
        </thead>
    </table>
    

    有关代码和演示,请参阅this jsFiddle

    【讨论】:

    • 我对我的问题进行了编辑。主要目标是列不那么宽。但是,添加 br 时宽度保持完全相同,即在本例中为 81px。你知道让它们变小的方法吗?
    • @Toskan,每列使用columns.width。另请参阅autoWidth 选项。
    【解决方案2】:

    根据您的表的初始化方式,您可以在columns 定义中使用title 键的改编:

    "title": "Your Title".split(" ").join("<br/>"), // Your<br/>Title
    

    Example JSFiddle here.

    【讨论】:

    • 和@Gyrocode.com的回答基本一致
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2020-07-27
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    相关资源
    最近更新 更多