admin管理员组文章数量:1297026
Could you please tell me how to update the selected row in the jquery data tables?
In the below code I am trying to set a cell. Looks like it is set but not reflecting in the table.
var datatable = $('#table').DataTable();
datatable.row('.selected').cell(':eq(1)').data("1234");
alert(datatable.row('.selected').cell(':eq(1)').data());
Here able to alert the changed value but the same is not reflecting in the data table UI. Can you help me?
Could you please tell me how to update the selected row in the jquery data tables?
In the below code I am trying to set a cell. Looks like it is set but not reflecting in the table.
var datatable = $('#table').DataTable();
datatable.row('.selected').cell(':eq(1)').data("1234");
alert(datatable.row('.selected').cell(':eq(1)').data());
Here able to alert the changed value but the same is not reflecting in the data table UI. Can you help me?
Share Improve this question asked Jul 24, 2016 at 9:46 manohar emanohar e 3273 gold badges6 silver badges17 bronze badges4 Answers
Reset to default 4Official documentation
draw() Since: DataTables 1.10 Redraw the table.
Description When you perform an action such as adding or deleting a row, changing the sorting, filtering or paging characteristics of the table you'll want DataTables to update the display to reflect these changes. This function is provided for that purpose.
your code is correct but datatables won't apply changes automatically, just call the draw() function.
datatable.row('.selected').cell(':eq(1)').data('123').draw();
You have to redraw the table using .draw()
method as mentioned in the documentation of cell().data() method:
Note that when used as a setter, this method sets the data to apply to the table, storing it in the data source array or object for the row, but does not update the table's internal caches of the data (i.e. the search and order cache) until the draw() method is called.
datatable.row('.selected').cell(':eq(1)').data("1234").draw();
Check the documentation
For me, this was the solution:
var t = $('#myTable').DataTable();
t.cell('.selectedRow', ':eq(0)').data('something data');
t.cell('.selectedRow', ':eq(1)').data('something data');
t.cell('.selectedRow', ':eq(2)').data('something data');
t.draw();
// selectedRowIndex should be global var selectedRowIndex = oTable.row(this).index();
// At the time of updating data in the selected row, do this oTable.cell(selectedRowIndex,2).data("xyz"); // where 2 is the cell index
// it will reflect the data in the grid. :)
https://datatables/reference/api/row().index()
本文标签: javascriptHow to update selected row in jquery data tablesStack Overflow
版权声明:本文标题:javascript - How to update selected row in jquery data tables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647968a2390301.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论