更新Jquery数据表单元格值 [英] Update Jquery Datatable Cell Value

查看:72
本文介绍了更新Jquery数据表单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery数据表,其中包含许多跨度.该表从数据库中加载了ajax数据,然后当用户更改值时,跨度将动态更新,以使所有其他跨度与同一类匹配.

I have a jquery datatable with a many spans in it. The table is loaded in with ajax data from a DB then the spans are dynamically updated to match all the other spans with the same class when a user changed a value.

我遇到的问题是,当我更新spans数据表时,似乎并不知道它已被更新.

The issue I am having though is that when I update the spans datatable doesn't seem to know it was updated.

例如,如果我将值更新为555,然后搜索555,则不会返回结果.

For example if I make update the value to 555 and then search for 555 it doesn't return a result.

我尝试使用.draw(),但是它似乎不起作用.我如何在不破坏和重建表的情况下更新数据表的所有单元格值.销毁似乎就像是巨大的杀伤力.

I tried to use .draw() but it doesn't seem to work. How do I have datatable update all the cell values without destroying and rebuilding the table. Destroy just seems like massive overkill.

推荐答案

我已经对此进行了一段时间的探讨,我认为这可能与数据表使用的缓存有关.但是我发现,如果找到该单元格,则将data属性设置为该单元格的html值即可.到目前为止,您将做这样的事情.

I have been beating on this for a while now and I think it may have to do with cache that datatable uses. What I found though was that if you find the cell then set the data attribute to the html value of the cell it works. So far example you would do something like this.

var UpdateTD = $(".changemade").parent('td');
table.cell( UpdateTD ).data( UpdateTD.html()).draw();

那确实是我发现使其起作用的唯一方法.这似乎并不是执行此操作的最佳方法,但它确实有效.这是更新的小提琴,在操作中显示了它 https://jsfiddle.net/jebwq9yL/1/

That is really the only way I have found to make to make it work. It doesn't really seem like the best way to do this, but it does seem to work. Here is the updated fiddle showing it in action https://jsfiddle.net/jebwq9yL/1/

这篇关于更新Jquery数据表单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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