如何在jquery数据表中添加新行并重新初始化它 [英] how to add a new row in jquery datatable and reinitialize it
问题描述
我正在以字符串格式创建一个新行,例如s =
I'm creating a new row in string format like s="
<tr><td></td></tr>
并通过webmethod将其返回给ajax。
ajax({
类型:POST,
url:notification.aspx / ReturnTableRow,
数据:JSON.stringify({maxidfetched:maxid ,empid:empid}),
contentType:application / json; charset = utf-8,
dataType:json,
beforeSend:function(){
},
succ ess:function(response){
if(response.d.trim()!=){
tbl.prepend(response.d);
}
},
失败:功能(响应){
//alert(response.d);
}
});
response.d以字符串形式返回行元素。
我有tbl,它被初始化为datatable,并且行将被添加到它。
但是在向tbl添加行后如何重新初始化它?
表格加载如果我初始化tbl然后创建数据表结构。
但是之后在行元素前面加上结构被破坏。
互联网有很多帮助可以添加行作为
rows.add(
[]);
但它只是添加单元格并创建一个新行。它没有灵活性。
II想写一个tr元素然后怎么做?
"
and returning it by webmethod to ajax.
ajax({
type: "POST",
url: "notification.aspx/ReturnTableRow",
data: JSON.stringify({ maxidfetched: maxid, empid: empid }),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
},
success: function (response) {
if (response.d.trim() != "") {
tbl.prepend(response.d);
}
},
failure: function (response) {
//alert(response.d);
}
});
response.d is returned row element as string.
I have tbl which is initialized as datatable and row will be added to it.
but after adding row to tbl how to reinitialize it?
on form load if I initialize tbl then datatable structure is created.
but after prepending the row element the structure destroyed.
There are many helps in internet to add rows as
rows.add(
[]);
but it just add cells and create a new row.It doesn't have flexibility.
I I want to write a tr element then how to do it?
推荐答案
tbl.prepend(
(response.d ));
(response.d));
尝试上面的代码而不是tbl.prepend(response.d),因为prepend()只接受元素作为参数。
try the above code instead of tbl.prepend(response.d), because the "prepend()" only accepts elements as parameter.
这篇关于如何在jquery数据表中添加新行并重新初始化它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!