Jquery Datatables可以很好地处理我的数据,直到我尝试为列添加页眉和页脚
我有以下HTML:Jquery Datatables可以很好地处理我的数据,直到我尝试为列添加页眉和页脚,jquery,datatables,Jquery,Datatables,我有以下HTML: <table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%"> <!--<thead> <tr> <th>Name</th> <th>
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<!--<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th class="disabled-sorting text-right">Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Description</th>
<th class="text-right">Actions</th>
</tr>
</tfoot>-->
</table>
页眉和页脚现在被注释掉,当我这样做时,我的数据显示在表中。但是当我取消注释页眉和页脚时,我没有得到任何数据,只有页眉和页脚!我做错了什么
另外,我知道datatables支持ajax调用,由于我调用的API进行身份验证的方式,它必须是一个单独的调用,并且按照我这里的方式填充,而不使用内置的ajax
我知道我在做一些非常愚蠢的事情,但那会是什么呢
更新:需要添加到“操作”列的操作:
<td class="text-right">
<a href="#" class="btn btn-simple btn-info btn-icon like"><i class="material-icons">favorite</i></a>
<a href="#" class="btn btn-simple btn-warning btn-icon edit"><i class="material-icons">dvr</i></a>
<a href="#" class="btn btn-simple btn-danger btn-icon remove"><i class="material-icons">close</i></a>
</td>
您需要设置选项fixedHeader.header和fixedHeader.footer:
fixedHeader: {
header: true,
footer: true
}
试试这个:
$('#datatables').DataTable( {
"data":resultA,
"columns": [
{ "data": "name" },
{ "data": "description" },
{
"data":null
"defaultContent":"<a href='#' class='btn btn-simple btn-info btn-icon like'><i class='material-icons'>favorite</i></a>
<a href='#' class='btn btn-simple btn-warning btn-icon edit'><i class='material-icons'>dvr</i></a>
<a href='#' class='btn btn-simple btn-danger btn-icon remove'><i class='material-icons'>close</i></a>"
}
],
fixedHeader: {
header: true,
footer: true
}
});
$('#datatables')。DataTable({
“数据”:结果,
“栏目”:[
{“数据”:“名称”},
{“数据”:“描述”},
{
“数据”:空
“defaultContent”:
"
}
],
固定标题:{
标题:对,
页脚:对
}
});
更多详细信息。执行此操作时,数据仍然显示,但我仍然没有页眉或页脚?在列中,您只指定了2列。在HTML中我看到3。行动专栏呢?天哪。我是个白痴!谢谢我已经把你的答案标记为“正确”,但我还有一个问题,你有时间吗?我已经更新了上面的问题,以显示我想要的行动。。。如果我想将其添加到每个操作行中,我将如何操作?为此,请使用defaultContent选项。这可能应该是一个单独的问题。
$('#datatables').DataTable( {
"data":resultA,
"columns": [
{ "data": "name" },
{ "data": "description" },
{
"data":null
"defaultContent":"<a href='#' class='btn btn-simple btn-info btn-icon like'><i class='material-icons'>favorite</i></a>
<a href='#' class='btn btn-simple btn-warning btn-icon edit'><i class='material-icons'>dvr</i></a>
<a href='#' class='btn btn-simple btn-danger btn-icon remove'><i class='material-icons'>close</i></a>"
}
],
fixedHeader: {
header: true,
footer: true
}
});