jquery数据表显示创建表行运行时后表中没有可用数据(javascript) [英] jquery datatable display No data available in table after creting table Row runtime(javascript)
问题描述
我正在尝试显示我从 JavaScript
创建的数据表(Jquery DataTable
)但有些表格是这样显示的.
i am trying to display table(Jquery DataTable
) of data witch i created from JavaScript
but some how the table is display like this .
Jquery DataTable
正确显示但功能不起作用,即使我进行搜索然后它显示通知 表中没有可用数据
即使我在页面中右键单击并 View Page Source
新行也不会显示它们.我不知道有什么问题,我把初始化数据表的代码,
Jquery DataTable
Properly display but the functionality is not working even if i do search then it display notification No data available in table
Even if i do right click in page and View Page Source
the new Row is not display their.
I don't no what is the problem hear i put the code of initialization for data table ,
$(document).ready(function() {
$('#example').dataTable({
"sPaginationType" : "full_numbers"
});
});
表中插入行代码
$("#example").find("tr:not(:first)").remove();
for (var i = 0; i < response.userListReturns.length; i++) {
var table = document.getElementById("example");
var thisRowCount = table.rows.length;
var row = table.insertRow(thisRowCount);
var cell1 = row.insertCell(0);
cell1.style.paddingTop = '4px';
cell1.style.paddingBottom = '4px';
cell1.style.textAlign = "center";
if(i%2!=0)
cell1.style.backgroundColor="#BAD6F7";
var element0 = document.createElement("input");
element0.type = "radio";
element0.id = "chkEditDelet"+i;
cell1.appendChild(element0);
var cell2 = row.insertCell(1);
cell2.style.paddingTop = '4px';
cell2.style.paddingBottom = '4px';
cell2.style.textAlign = "left";
if(i%2!=0)
cell2.style.backgroundColor="#BAD6F7";
cell2.innerHTML= i+1;
var cell3 = row.insertCell(2);
cell3.style.paddingTop = '4px';
cell3.style.paddingBottom = '4px';
cell3.style.textAlign = "left";
if(i%2!=0)
cell3.style.backgroundColor="#BAD6F7";//c4ffc4
cell3.style.whiteSpace="nowrap";
cell3.innerHTML= response.userListReturns[i].userName;
var cell4 = row.insertCell(3);
cell4.style.paddingTop = '4px';
cell4.style.paddingBottom = '4px';
cell4.style.textAlign = "left";
if(i%2!=0)
cell4.style.backgroundColor="#BAD6F7";//c4ffc4
cell4.innerHTML= response.userListReturns[i].userAddress;
var cell5 = row.insertCell(4);
cell5.style.paddingTop = '4px';
cell5.style.paddingBottom = '4px';
cell5.style.textAlign = "left";
if(i%2!=0)
cell5.style.backgroundColor="#BAD6F7";//c4ffc4
cell5.innerHTML= response.userListReturns[i].userPhoneNo;
var cell6 = row.insertCell(5);
cell6.style.paddingTop = '4px';
cell6.style.paddingBottom = '4px';
cell6.style.textAlign = "left";
if(i%2!=0)
cell6.style.backgroundColor="#BAD6F7";//c4ffc4
cell6.innerHTML= response.userListReturns[i].education;
var cell7 = row.insertCell(6);
cell7.style.paddingTop = '4px';
cell7.style.paddingBottom = '4px';
cell7.style.textAlign = "left";
if(i%2!=0)
cell7.style.backgroundColor="#BAD6F7";//c4ffc4
cell7.innerHTML= response.userListReturns[i].userLiginName;
var cell8 = row.insertCell(7);
cell8.style.paddingTop = '4px';
cell8.style.paddingBottom = '4px';
cell8.style.textAlign = "left";
if(i%2!=0)
cell8.style.backgroundColor="#BAD6F7";//c4ffc4
cell8.innerHTML= '********';
}
推荐答案
看来您正在手动添加行,我不确定这是否适用于数据表.我建议你阅读那里的 api,如果你坚持这样做,你可以直接从网站使用 fnAddData,用法如下:
It seems you are adding the rows manually and I am not sure that will work well with datatables. I recommend you read there api and if you insist on doing it this way you can use fnAddData, straight from the site the usage looks like:
var giCount = 2;
$(document).ready(function() {
$('#example').dataTable();
} );
function fnClickAddRow() {
$('#example').dataTable().fnAddData( [
giCount+".1",
giCount+".2",
giCount+".3",
giCount+".4" ]
);
giCount++;
}
然后您仍然可以通过 css 设置表格的样式.
you can then still style the table through css.
这篇关于jquery数据表显示创建表行运行时后表中没有可用数据(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!