刷新Jquery Datatable中的排序缓存 [英] Refreshing sort cache in Jquery Datatable

查看:93
本文介绍了刷新Jquery Datatable中的排序缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到,当第一次使用

I can see that Jquery datatables generates a sorting cache when the table is first initialized using the table.columns().cache() method. One of my columns contains td elements that have a span with classes on it. Example:

<tr>...<td><span class="SpanColors red"></span></td>...</tr>
...
<tr>...<td><span class="SpanColors blue"></span></td>...</tr>

我对此特定列的排序取决于跨度上的类.我已经写了一个基于文本的列排序功能来做到这一点,如此处所述.

My sorting of this particular column depends on the class that is on the span. I have written a text-based column sorting function to do this, as described here.

在我的表中,我以这种方式动态更新行:

In my table, I am dynamically updating rows in this way:

var id = //some guid
var newClassToAdd = 'yellow';
var rows = table.rows().nodes();
for (var i = 0; i < rows.length; i++) {
    var row = $(rows[i]);
    var span = row.find('td span.SpanColors')
    if (span && span.data('id') == id) {
        span.removeClass('red blue yellow');
        span.addClass(newClassToAdd);
    }
}

我遇到的问题是,执行此操作时,缓存不会更新,因此在排序时,行的显示顺序与更新时的顺序相同.

The issue that I am running into is that when I do this, the cache isn't updated so when sorting, the rows appear in the same order as prior to when I updated them.

在更新行之后,是否可以使用某些方法来更新此缓存?我已经搜索过互联网,但是显然这不是很多人遇到的问题.也许如果我以另一种(更合理的)方式更新行,则缓存是否可以自行刷新?

Is there some method that can be used to update this cache after rows are updated? I have searched the internet, but apparently this isn't a problem that many people are having. Perhaps if I were updating my rows in a different (more legitimate) way, the cache, might refresh on its own?

推荐答案

您可能可以使用

You can probably use row().invalidate() after you're done modifying cell content.

table.row(rows[i]).invalidate('dom');

所有行均无效后,您可能需要调用 draw() 重绘桌子.

After all rows are invalidated you may need to call draw() to redraw the table.

这篇关于刷新Jquery Datatable中的排序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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