jquery - 使用jQuery在数据表中动态添加列

标签 jquery mysql css

这是我的 table 。我无法向表中动态添加额外的列。请帮忙。

<table id="example" class="table table-striped table-bordered compact table-hover" width="100%" cellspacing="0">
    <thead>
        <tr>
            <th>Part List</th>
            <th>Score</th>
            <th>Project 1</th>
            <th>Final Score</th>
            <th>Target Setting</th>
            <th width="86px">Check box</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>
                <input type="checkbox" id="usr" />
            </td>
        </tr>
    </tbody>
</table>

这是我的脚本。

var tabl = 0;
$(document).ready(function () {
    tabl = \$('#example').dataTable({
        "sScrollY": "300px",
            "scrollCollapse": true,
            "paging": false,
            "bInfo": false,
            "bSort": false,
    });
});    

最佳答案

Create a two dynamic array aaColumnAllAns,aaDatavalAllAns  
var aaColumnAllAns =[];   
var aaDatavalAllAns = [];   
start the loop after ajax return    
/$.post('testpage',array),function(data) {    
var productlist = data.prdlst;    
  /$.each(productlist, function(key, value) {    
     aaDatavalAllAns.push({"0":value.id,"1":value.name})    
  });    
 aaColumnAllAns.push({ "sTitle": "ID" },{ "sTitle":"NAME"}    
})
table =$('#example').dataTable({                                                                                              
"sScrollY": "300px",                                                                       
"scrollCollapse": true,                                                                                      
"paging": false,
"bInfo": false,                                                                                                       
"bSort": false,                                                                             
"aoColumns":aaColumnAllAns,
"aaData": aaDatavalAllAns
});

关于jquery - 使用jQuery在数据表中动态添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27777975/

相关文章:

mysql - C(树莓派)从文本文件中读取不同长度的行

mysql - 计算最近n场比赛的总和 Mysql

html - 如何让下拉菜单竖排

html - 非常奇怪但非常烦人的 JQuery 移动问题

jquery - Request.IsAjaxRequest() 在 MVC4 中总是返回 false,尝试了 SO 中的所有建议等

javascript - 在鼠标悬停事件上触发 Bootstrap 折叠功能

javascript - 使用 window.onload 时 Bootstrap 轮播不会自动开始滑动

jquery简单图像缩放

MySQL子查询引用其范围之外的表

jquery - 如何创 build 备固定的容器?