Javascript 用可变数量的数据单元填充HTML表页脚。数据表
我正在努力做到以下几点Javascript 用可变数量的数据单元填充HTML表页脚。数据表,javascript,jquery,html,datatable,Javascript,Jquery,Html,Datatable,我正在努力做到以下几点 <table class="table table-striped table-small downloadable" id="example"> <thead></thead> <tfoot></tfoot> </table> 我得到了一个大小不一的html表格。大小取决于Sql查询的结果,因此可能是4x4表或nxn表,这始终取决于Sql查询 <table class="table tab
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
我得到了一个大小不一的html表格。大小取决于Sql查询的结果,因此可能是4x4表或nxn表,这始终取决于Sql查询
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
下面是填充dataTable对象的代码。dataset是一个数组,包含所有值,datatitle包含所有标题
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
所有这些工作都非常好,生成了漂亮的表格
$('#Example').dataTable({
"deferRender": true,
"order":[[1,'asc']],
scrollX: true,"data": dataset,
"columns": datatitle,
}
});
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
我的HTML代码如下所示:
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
我现在要做的是用相应列的和值填充Footerrow。如果我添加了同样多的代码,下面的代码就可以工作了
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
<td></td>
到页脚行,如下所示。在本例中,它将为我提供前两列的摘要
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
<tfoot> <td></td> <td></td> </tfoot>
var table = $('#'+example).DataTable();
table.columns( ).every(function(){;
$( this.footer()).html( this.data().reduce(
function (a,b) {
a = parseInt(a);
b = parseInt(b);
return a+b; } ));
});
$(table.column(0).footer()).html("Gesamt");
}
var table=$('#'+示例).DataTable();
table.columns().every(function(){;
$(this.footer()).html(this.data().reduce(
函数(a,b){
a=parseInt(a);
b=parseInt(b);
返回a+b;});
});
$(table.column(0.footer()).html(“Gesamt”);
}
我要做的是使这个变量不必在我的HTML页脚元素中输入一定数量的“
单元格
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>
谢谢你的帮助。我希望除了用JS将其破解到HTML文档中之外,还有一个解决方案
<table class="table table-striped table-small downloadable" id="example">
<thead></thead>
<tfoot></tfoot>
</table>