简体   繁体   English

如何使用数据表更新所有表中的所有单元格

[英]How to update all cells in all tables with datatable

I have multiple datatables in the same page where their class name is 'datatable-responsive'. 我在同一个页面中有多个数据表,它们的类名是“响应数据表”。 I want to update the contente of each cell in each table... 我想更新每个表中每个单元格的内容...

$('.datatable-responsive').each( function(i){
  var table = $(this).dataTable();

  table.cell('.normal-1').data(valToSet).draw();
});

When I inspect thru firebug the "tables", I get 3 tables but it's not entering in the loop. 当我通过萤火虫检查“表”时,我得到3个表,但它没有进入循环。 How can I do that? 我怎样才能做到这一点?

EDIT 编辑

Here's the jsFiddle 这是jsFiddle

I think you're trying to target the child element incorrectly. 我认为您尝试错误地定位子元素。 Instead of using table.cell('.normal-1') try using $(table).find('.normal-1'); 而不是使用table.cell('.normal-1')尝试使用$(table).find('.normal-1');

I substituted this in your fiddle and it's targeting the correct element however I'm still getting an error on the console saying valToSet is not defined which I think might be a different issue. 我用您的小提琴代替了它,它的目标是正确的元素,但是在控制台上仍然出现错误, valToSet is not defined ,我认为这可能是另一个问题。 Hope that helps! 希望有帮助!

Edit 编辑

Also... the reason why your loop isn't completing is because of the valToSet not defined error is stopping the loop. 另外...循环未完成的原因是由于valToSet not defined错误正在停止循环。 Comment this line out and you will see your tables in the console. 注释掉这一行,您将在控制台中看到表。

You need to invalidate() the cell in order to update the internal preprocessed sorting for the column : 您需要invalidate()单元格以更新列的内部预处理排序:

var table = $(this).DataTable();
table.cell(selector).data(randomNewVal).invalidate().draw();

updated fiddle -> https://jsfiddle.net/fnj0eb4m/11/ 更新小提琴-> https://jsfiddle.net/fnj0eb4m/11/

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

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