首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为DataTables插件显示排序箭头?

问如何为DataTables插件显示排序箭头?
EN

Stack Overflow用户
提问于 2016-09-28 02:19:16
回答 1查看 5.3K关注 0票数 2

我已经为我的html表格设置了DataTables插件,但是,虽然点击顶部一行会使表格按点击的列排序,但是排序箭头并没有显示出来。

这就是我引用DataTable资产的方式(通过CDN):

代码语言:javascript
复制
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

然后我像这样戳这个插件:

代码语言:javascript
复制
$('#delperfTable').DataTable({
    "paging": false,
    "info": false,
    "searching": false
});

排序工作正常,但不显示方便的可视指示器。我想,如何才能让这些排序箭头按照默认行为显示呢?

我在谷歌上看到了一些关于需要“拉出图像”的信息,但如果可能的话,我想通过CDN参考这些图像。

更新

注意:我还有:

代码语言:javascript
复制
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

HTML是:

代码语言:javascript
复制
<div class="col-md-6">
    <div class="bottomright">
        <h2 class="sectiontext">Delivery Performance</h2>
        <table id="delperfTable">
            <thead>
                <tr>
                    <th>PRO*ACT Distributor</th>
                    <th>Restaurant Location</th>
                    <th class="rightjustifytext">Avg Order Amount</th>
                    <th class="rightjustifytext">Avg Package Count</th>
                    <th class="rightjustifytext">Total Sales</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Sunrise FL</td>
                    <td>A1A ALEWORKS - #4405 - ST. AUGUSTINE</td>
                    <td class="rightjustifytext">$475.78</td>
                    <td class="rightjustifytext">28.50</td>
                    <td class="rightjustifytext">$1,903.10</td>
                </tr>
                . . . // other trs elided for brevity
                <tr class="bold">
                    <td>TOTAL</td>
                    <td></td>
                    <td class="rightjustifytext">375.11</td>
                    <td class="rightjustifytext">23.50</td>
                    <td class="rightjustifytext">$7,966.68</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

更新2

我添加了两个类,一个添加到表中,一个添加到列中,如下所示:

代码语言:javascript
复制
<table id="delperfTable" class="dataTable">
    <thead>
        <tr>
            <th class="sorting">PRO*ACT Distributor</th>

...but它没有什么不同。

更新3

下面是表在运行时被检查时的外观:

​

​

EN

回答 1

Stack Overflow用户

发布于 2020-06-04 00:30:37

您的代码在以下行中缺少rel="stylesheet":

代码语言:javascript
复制
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />

这会导致浏览器静默地无法包含dataTables.bootstrap.min.css,这是表排序上/下箭头显示的位置。

在DataTables 1.10.21中,dataTables.bootstrap.css (用于Bootstrap 3)包含:

代码语言:javascript
复制
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:after,
table.dataTable thead .sorting_asc_disabled:after,
table.dataTable thead .sorting_desc_disabled:after {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: block;
  font-family: 'Glyphicons Halflings';
  opacity: 0.5;
}
table.dataTable thead .sorting:after {
  opacity: 0.2;
  content: "\e150";
  /* sort */
}
table.dataTable thead .sorting_asc:after {
  content: "\e155";
  /* sort-by-attributes */
}
table.dataTable thead .sorting_desc:after {
  content: "\e156";
  /* sort-by-attributes-alt */
}

如果使用的是Bootstrap 4,则要使用的文件是dataTables.bootstrap4.css

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39731718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档