如何在jQuery DataTables上重新初始化数据排序? [英] How to re-initialise data-sort on jQuery DataTables?
问题描述
我在我的项目中使用jQuery Datatables,并且通过使用属性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.
直接对属性进行更新,例如:
Update is done on the attribute directly as such:
$('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()
单元格. dataTable没有机会知道您已经以编程方式更改了列中一个或多个单元格的正交数据(=自定义排序值).如果您有
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);
然后invalidate
通过
table.cells("#myColumnId").invalidate();
这篇关于如何在jQuery DataTables上重新初始化数据排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!