如何在 jQuery DataTables 上重新初始化数据排序? [英] How to re-initialise data-sort on jQuery DataTables?

查看:49
本文介绍了如何在 jQuery DataTables 上重新初始化数据排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 jQuery 数据表,并且通过使用属性 data-sort 对列进行了自定义值"排序,如下所述:https://datatables.net/examples/advanced_init/html5-data-attributes.html

I am using jQuery Datatables in my project and I have made "custom value" sorting available on a column by using the attribute data-sort as described here: https://datatables.net/examples/advanced_init/html5-data-attributes.html

工作正常.但是现在我使用 Javascript/jQuery 来更新这些属性的值,并且 dataTable 没有考虑新值,它仍然使用原始值进行排序.

Works fine. But now I am using Javascript/jQuery to update the values of these attributes, and the dataTable doesn't take into account the new values, it still sorts using the original values.

直接对属性进行更新:

$('td#myColumnId').attr('data-order', newValue);

如何强制我的 dataTable 重新初始化我的自定义排序值?

How can I force my dataTable to re-initialise my custom sort values?

到目前为止,我已经尝试过 .draw().dataTable() 但不幸的是这不起作用.

So far I have tried .draw() and .dataTable() but unfortunately that is not working.

我期待一个可能的解决方案.

I'm looking forward to a possible solution.

推荐答案

你需要invalidate() 单元格.dataTables 没有机会知道您以编程方式更改了一列中一个或多个单元格的正交数据(=自定义排序值).如果你有一个像

You need to invalidate() the cell(s). dataTables have no chance to know that you programmatically have changed orthogonal data (=the custom sort values) for one or more cells in a column. If you have an instance like

var table = $('#example').DataTable();

并通过

$('td#myColumnId').attr('data-order', newValue);

然后使单元格/列无效

table.cells("#myColumnId").invalidate();

这篇关于如何在 jQuery DataTables 上重新初始化数据排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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