javascript - How to know index of DataTable row just added?
问题描述
I am using the DataTables jQuery plugin version 1.10.22.
I add a row to DataTable, like the following.
var table = $('#example').DataTable();
var data = { Id: 0, Name: 'Fred', Age: 42 };
table.row.add( data ).draw( false );
That works. A new row is added to the table, and the data I provided is displayed.
But, immediately after adding the row, I would like to know the row index of that row I just added. How do I determine that?
解决方案
The row.add()
function returns an instance of a DataTable object containing the new row (and only the new row):
var newRow = table.row.add( data ).draw( false );
So, now you can get the assigned index from that:
console.log(newRow.index());
This is the internal DataTables index of the row - not the visual/displayed position index in the HTML table. This value does not change as the table is sorted/filtered.
推荐阅读
- date - H:M格式linux ubuntu中的两次总和
- android - 需要将 Firebase 响应存储在 arraylist 中
- javascript - 我的函数返回一个字符串,但比较总是错误的
- selenium - 当我们不知道我们在点击什么时,如何在 selenium 中获取点击的元素
- r - 有没有办法在传单上绘制 ggplots 而不将它们保存在光盘上?
- cobalt - 切换系统菜单时的应用程序生命周期测试:onvisibilityChange:hidden 时屏幕变黑
- node.js - Node JS 在单个“事务”中将多条记录保存到 Mongo
- java - Android 导航架构组件:如何将捆绑数据传递给 startDestination
- sqlite - 是否有替换部分字符串的功能?
- java - 如何让我的代码运行 LoginActivity.java