- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够成功创建dataTable
这是演示:https://jsfiddle.net/w2nevcca/3/
添加时出现问题
<tr>
<th class="widthind">14/11/2017</th>
</tr>
<!-- added as date divider -->
当我将上面的 code
添加为 divider
以显示我的 date
这是第二个 演示(不工作):https://jsfiddle.net/pkxmnh2a/12/
下面是我的代码
HTML:
<div class="table-content table-responsive">
<table id="examples" class="display tvalues" cellspacing="0" width="100%" name="tabel">
<thead>
<tr>
<!--th>ID</th-->
<th>User Id</th>
<th>User Name</th>
<th>Project Name</th>
<th>Work Description</th>
<!--<th>Reported On</th>-->
</tr>
</thead>
<tfoot>
<tr>
<!--th>ID</th-->
<th>User Id</th>
<th>User Name</th>
<th>Project Name</th>
<th>Work Description</th>
<!-- <th>Reported On</th>-->
</tr>
</tfoot>
<tbody>
<tr>
<th class="widthind">14/11/2017</th>
</tr>
<tr>
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 2222</p>
</td>
</tr>
<tr>
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 33333</p>
</td>
</tr>
<tr>
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 44444</p>
</td>
</tr>
<tr>
<th class="widthind">13/11/2017</th>
</tr>
<tr>
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>yesterday report</td>
<td>
<p>this my yesterday day report employeee 2222</p>
</td>
</tr>
<tr>
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>yesterday report</td>
<td>
<p>this my yesterday day report employeee 33333</p>
</td>
</tr>
</tbody>
</table>
</div>
下面是我的javascript代码
JS:
$(document).ready(function () {
var table = $('#examples').DataTable();
$('a.toggle-vis').on('click', function (e) {
e.preventDefault();
var column = table.column($(this).attr('data-column'));
column.visible(!column.visible());
});
$('#examples tfoot th').each(function () {
var title = $('#examples thead th').eq($(this).index()).text();
$(this).html('<input tyepe="text" placeholder="Search ' + title + '"/>');
});
table.columns().eq(0).each(function (colIdx) {
$('input', table.column(colIdx).footer()).on('keyup change', function () {
table
.column(colIdx)
.search(this.value)
.draw();
});
});
});
当我不添加分隔符来显示日期时,上面的代码工作得很好
当我添加分隔符时,上面的代码不起作用。
请提前帮助我谢谢!!!!
最佳答案
如果您查看浏览器开发人员工具的控制台(通过按键盘上的 F12 打开),您会发现存在 JavaScript 错误。这实际上是阻止数据表呈现的原因。
此错误的原因是 DataTables 没有准备好遇到这样的行 - 它希望所有行都以相同的格式(和相同数量的列)保存数据。
虽然您可以通过插入三个空的 <th>
来消除错误单元格添加到标题行(colspan
在这里不起作用),从而使 DataTable 呈现(请参阅 https://jsfiddle.net/n34vbnmd/1)- DataTables 应该如何知道如何在排序时处理这些行?
更好的解决方案是在每次渲染后动态插入这些行。您需要对应该具有公共(public)标题行的行进行分组,例如使用自定义数据属性。然后你可以使用 fnDrawCallback
通过 DataTable 的选项进行回调,以便在重绘 DataTable 时生成这些标题行。
您可能还想查看有关“行分组”的官方文档: https://datatables.net/examples/advanced_init/row_grouping.html - 我刚发现这个,但它基本上和我的例子一样。请注意,我没有用多个页面等彻底测试我的示例,文档中提供的代码似乎可以更好地处理这个问题!
$(document).ready(function () {
var table = $('#examples').DataTable({
"fnDrawCallback": function() {
var currentGroup = null;
$(this).find('tbody tr').each(function() {
var thisRow = $(this),
rowGroup = thisRow.attr('data-group');
if (rowGroup != currentGroup) {
currentGroup = rowGroup;
thisRow.before('<tr class="widthind"><th colspan="4">' + rowGroup + '</th></tr>');
}
});
}
});
$('a.toggle-vis').on('click', function (e) {
e.preventDefault();
var column = table.column($(this).attr('data-column'));
column.visible(!column.visible());
});
$('#examples tfoot th').each(function () {
var title = $('#examples thead th').eq($(this).index()).text();
$(this).html('<input tyepe="text" placeholder="Search ' + title + '"/>');
});
table.columns().eq(0).each(function (colIdx) {
$('input', table.column(colIdx).footer()).on('keyup change', function () {
table
.column(colIdx)
.search(this.value)
.draw();
});
});
});
.widthind th {
background-color: black;
color: white;
text-align: left;
}
<link href="https://cdn.datatables.net/1.10.0/css/jquery.dataTables.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.js"></script>
<div class="table-content table-responsive">
<table id="examples" class="display tvalues" cellspacing="0" width="100%" name="tabel">
<thead>
<tr>
<!--th>ID</th-->
<th>User Id</th>
<th>User Name</th>
<th>Project Name</th>
<th>Work Description</th>
<!--<th>Reported On</th>-->
</tr>
</thead>
<tfoot>
<tr>
<!--th>ID</th-->
<th>User Id</th>
<th>User Name</th>
<th>Project Name</th>
<th>Work Description</th>
<!-- <th>Reported On</th>-->
</tr>
</tfoot>
<tbody>
<tr data-group="14/11/2017">
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 2222</p>
</td>
</tr>
<tr data-group="14/11/2017">
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 33333</p>
</td>
</tr>
<tr data-group="14/11/2017">
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>today's day report</td>
<td>
<p>this my first day report employeee 44444</p>
</td>
</tr>
<tr data-group="13/11/2017">
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>yesterday report</td>
<td>
<p>this my yesterday day report employeee 2222</p>
</td>
</tr>
<tr data-group="13/11/2017">
<td>9cbc6e5a99bf96a61e5fa0445315286f</td>
<td>arjun</td>
<td>yesterday report</td>
<td>
<p>this my yesterday day report employeee 33333</p>
</td>
</tr>
</tbody>
</table>
</div>
关于javascript - 如果添加了带有标题的新行,为什么 dataTable 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47334663/
我附上了一个我尝试使用 html/css 实现的示例(如果您看不到图像:名字和姓氏,然后第二行是职位描述)。我希望所有文本(两行)在一个 div 中强制对齐(左和右),但我不确定这是否可能。我尝试了一
我想使两个 h1 元素成为 div 上的标题/页眉。所以每个都在特定的 div 之上。 Youtube Achievements
我想让每个 EditText 对象都有自己的标题,就像 Pure Android 指南中那样 (screenshot) 这个东西有原生支持吗?我想他们也可能会使用带有部分的 ListView ,但这对
是否可以像 UITableView headerView 一样创建 UICollectionView 标题 View ?我的意思是整个集合 View 的标题 View ,而不是每个部分的重复 View
我一直在遵循有关排版的 Google 官方 Material 设计指南 (http://www.google.com/design/spec/style/typography.html),但我发现它们
我目前正在尝试找到可以帮助我从视频文件中提取元数据或信息的 python 库,例如 [ mp4, Mkv, Avi, WebM, mpg ] 格式为例。 我主要从视频文件中提取的主要数据是 [标题、描
你好, 这是我正在尝试做的: 将每个缩略图的内容(img + 标题)居中。我的 img 必须是 span3,标题必须是 span4。 这是我的问题: 我可以获取内容中心,或者标题 float 在 im
我有一个带有导航栏的应用程序,可以从一个 View Controller 导航到下一个 View Controller 。在某些模拟器和设备上导航到下一个 View Controller 时,后退按钮
我遇到了一些非常酷的 t-sql,可以从一个 t-sql 查询中的选定行生成一个逗号分隔的列值列表: SELECT @MyList = ISNULL(@MyList,'') + Title + ',
请确保将 HTML heading 标签只用于标题。不要仅仅是为了生成粗体或的文本而使用标题。 搜索引擎使用标题为您的网页的结构和内容编制索引。 因为用户可以通过标题来快速浏览您的网页,所以用标
我正在使用 wkhtmltopdf 将 html 转换为 pdf。 我想在每个页面中添加标题,但它只显示在第一页(目录)中。 我使用的命令是 "C:\Program Files\wkhtmltopdf
如何使用 ggplot2 显示观察的方向(标题)?有没有办法调整shape=17 (三角形)以便它“指向”下一次观察? 示例代码 library(ggplot2) dat % pivot_wide
我尝试在 cocoa 应用程序中显示/隐藏标题栏。我使用以下代码: if ([window styleMask]==NSResizableWindowMask) { [wind
我有这样的 HTML 标题 http://s1.postimg.org/4ebyk3qwv/image.png 当我编写这段代码时: document.getElementById("TL85_1_
我叫麦克。谢谢你的帮助。 在Wordpress中,我们已经设计了我们的网站,以便在Facebook调试器中og数据尽可能接近youtube。尽管如此,在Facebook上共享视频的方式还是不同的。尽管
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
我是 SAPUI5 的新手,在导航、侧边栏和标题方面遇到一些问题。我想开发一个带有标题和侧边栏的应用程序。我为此使用“ToolPage”。每个页面都包含工具页,如下所示:
我最近在为客户做的项目中被介绍给Go。他们已经建立了代码库,需要进行一些更改。 我注意到所有的方法,结构等等都有一些奇怪的类似于标题的注释,如下所示: // SomeType ... type Som
我创建了一个采用整个屏幕布局的标题布局(xml 文件)... 我还创建了一个 listView 并将此 header_layout 添加到 listView 中: LayoutInflater inf
我是一名优秀的程序员,十分优秀!