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

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

问题描述

我可以看到当表第一次使用 table.columns().cache() 方法.我的一列包含 td 元素,这些元素具有一个带有类的跨度.示例:

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?

推荐答案

你或许可以使用 row().invalidate() 修改完单元格内容后.

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 数据表中的排序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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