【发布时间】:2015-01-13 06:17:04
【问题描述】:
我想把复选框放到数据表中,输出来自Json数组,并使用javascript在html表中显示这些数组元素。
我想为每一行添加一个复选框,以便于编辑、删除。
HTML 代码为:
<table id="example1" class="table table-bordered table-striped num-right-alignct">
<thead>
<tr>
<th style="text-align: center;">Ad Headline</th>
<th style="text-align: center;">Ad ID</th>
<th style="text-align: center;">Ad Description 1</th>
<th style="text-align: center;">Ad Description 2</th>
<th style="text-align: center;">URL Appeared</th>
<th style="text-align: center;">Clicks</th>
<th style="text-align: center;">CPC</th>
<th style="text-align: center;">Conversions</th>
<th style="text-align: center;">CTR %</th>
<th style="text-align: center;">Impressions</th>
<th style="text-align: center;">Avg Pos</th>
<th style="text-align: center;">Cost</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
JS代码:
$("#groupid").change(function(){
var oTable = $('#example1').dataTable();
var grpvalue=$('#groupid').val();
$.ajax({
type:"post",
dataType : 'json',
url:"pages/ads.php",
data:"adgroup="+grpvalue,
success: function(s) {
oTable.fnClearTable();
for(var i = 0; i < s.length; i++) {
oTable.fnAddData([
s[i]['hea']["0"],
s[i]['id']["0"],
s[i]['desc']["0"],
s[i]['desc2']["0"],
s[i]['url']["0"],
s[i]['cli']["0"],
s[i]['cpc']["0"],
s[i]['con']["0"],
s[i]['ctr']["0"],
s[i]['imp']["0"],
s[i]['ap']["0"],
s[i]['cost']["0"]
]);
}
}
});
});
而且 html 表格数据是动态的,我想为每一行添加一个复选框。请告诉我执行此操作的过程。
【问题讨论】:
-
在
columns定义中使用render:fuunction()。查看文档 -
能否详细说明你的答案,以便我理解
-
阅读文档
-
几年后:现在,有一个很棒的插件,可以与服务器端一起使用,包括。选择更多:gyrocode.com/projects/jquery-datatables-checkboxes
标签: javascript php jquery html checkbox