简体   繁体   English

未为数据表中新添加的行定义行 ID?

[英]Row ID is undefined for new added row in datatables?

I think this is a repeated question, but I see all the answers and nothing clear?我认为这是一个重复的问题,但我看到了所有的答案,却一无所知? I used data tables in my MVC app and everything works perfectly, till I add a new row to this datatable using我在我的 MVC 应用程序中使用了数据表,一切正常,直到我使用向这个数据表添加一个新行

table.api().row.add 

after that, I assigned row id using two methods then draw 1-之后,我使用两种方法分配了行 ID,然后绘制 1-

row.nodes().to$().attr('id', ID)

2- 2-

row.node().id = ID

When I try to get the newly added row id using row.id its undefined and row.data not contain dt_rowid at all.当我尝试使用 row.id 获取新添加的行 ID 时,它的 undefined 和 row.data 根本不包含 dt_rowid。 In HTML I can see the id correctly added How to get the id for the newly added row Please help me在 HTML 我可以看到正确添加的 id 如何获取新添加行的 id 请帮助我

var table = $('#myTable').DataTable();
table.rows().every(function () {
var data = this.data();
var id = this.id();
console.log('Data id: ' + id);
});

Try this.尝试这个。 Please refer this link https://datatables.net/reference/api/rows().every()请参考此链接https://datatables.net/reference/api/rows().every()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM