Jquery:在数据表中添加自定义行 [英] Jquery: add custom row in datatables

查看:82
本文介绍了Jquery:在数据表中添加自定义行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个HTML页面,其中包含五列。最后一个包含一个按钮。 (每行在最后一列有一个按钮)。

I created an html page, which contains five columns. The last one contains a button. (Each row has a button in the last column).

我使用的是数据表插件:

I'm using datatables plugin:

var oTable = $(".datatable-fn").dataTable({
    sPaginationType: "full_numbers"
});

现在我需要在表中添加新行。我知道存在 fnAddData 这样做的功能,但是我不知道如何在行的最后一个单元格中添加按钮。

Now I need to add new row to the tables. I know that exists fnAddData function that do this, but I don't know how can I add the button in the last cell of the row.

推荐答案

您可以在新单元格中添加任何HTML内容:

You can add any HTML content in the new cells:

$('#example').dataTable().fnAddData( [
    giCount+".1",
    giCount+".2",
    giCount+".3",
    "<button>My button</button>" ] );

使用 createElement

var button = document.createElement("button");
button.innerHTML = "My button";

$('#example').dataTable().fnAddData( [
    giCount+".1",
    giCount+".2",
    giCount+".3",
    button.outerHTML  ] )

这篇关于Jquery:在数据表中添加自定义行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆