jquery datatables列未正确排序(jquery datatables column not sorting properly)

编程入门 行业动态 更新时间:2024-10-25 22:26:08
jquery datatables列未正确排序(jquery datatables column not sorting properly)

我想我知道这个问题,但我不知道如何正确处理它,所以我希望这里有人有类似的问题,并设法解决它的方式。 我所拥有的是一个包含几列的表,除了一个列之外,所有这些列都可以进行排序。 下面是该列的屏幕截图及其在工作中的排序。

正如您所看到的那样,它不会根据字母数字逻辑进行排序。 我的假设是某些名称中包含逗号括号,括号等字符。 所以说,我将如何处理这个问题,以便我可以使用datatables插件对这个alpha-numericly进行排序? 思想的?

****编辑****

这是我正在使用的代码,适用于除此列之外的所有内容..

jQuery.fn.dataTableExt.oSort['num-asc'] = function(a,b) { var x = a.replace( /<.*?>/g, "" ); var y = b.replace( /<.*?>/g, "" ); x = parseFloat( x ); y = parseFloat( y ); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jQuery.fn.dataTableExt.oSort['num-desc'] = function(a,b) { var x = a.replace( /<.*?>/g, "" ); var y = b.replace( /<.*?>/g, "" ); x = parseFloat( x ); y = parseFloat( y ); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; $(document).ready(function() { $('#ledger').dataTable({ bAutoWidth: false, bJQueryUI : true, bProcessing: true, bServerSide: false, sPaginationType: "full_numbers", bStateSave : false, bUseRendered: false, iDisplayLength: ${entriesValue}, sDom: mw.superadmin.datatable.relatedListDom, aLengthMenu: mw.superadmin.datatable.relatedListLengthMenu, aaSorting: [[0,'asc']], aoColumns: [ null, { "iDataSort": 2}, { "bVisible": false, "sType": "num"}, { "iDataSort": 4, "bSortable": true }, { "bVisible": false, "sType": "num"} ] });

I think I know the issue with this, but I do not know how to approach it properly so I am hoping someone here has had a similar issue and managed to fix it some how. What I have is a table with a few columns all of which work as far as sorting goes except one. below is a screen capture of that column and its sorting at work.

as you can see it does not sort according to alpha-numeric logic. My assumption is that some of the names have characters in them such as comma's parentheses, brackets, and so on. So that said, how would I tackle this issue so I can sort this alpha-numericly using the datatables plugin? Idea's?

****EDIT****

This is the code I am working with, works for everything but this one column..

jQuery.fn.dataTableExt.oSort['num-asc'] = function(a,b) { var x = a.replace( /<.*?>/g, "" ); var y = b.replace( /<.*?>/g, "" ); x = parseFloat( x ); y = parseFloat( y ); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; jQuery.fn.dataTableExt.oSort['num-desc'] = function(a,b) { var x = a.replace( /<.*?>/g, "" ); var y = b.replace( /<.*?>/g, "" ); x = parseFloat( x ); y = parseFloat( y ); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; $(document).ready(function() { $('#ledger').dataTable({ bAutoWidth: false, bJQueryUI : true, bProcessing: true, bServerSide: false, sPaginationType: "full_numbers", bStateSave : false, bUseRendered: false, iDisplayLength: ${entriesValue}, sDom: mw.superadmin.datatable.relatedListDom, aLengthMenu: mw.superadmin.datatable.relatedListLengthMenu, aaSorting: [[0,'asc']], aoColumns: [ null, { "iDataSort": 2}, { "bVisible": false, "sType": "num"}, { "iDataSort": 4, "bSortable": true }, { "bVisible": false, "sType": "num"} ] });

最满意答案

既然你正在显示一个链接,我猜你正在使用自定义渲染功能?

如果是这种情况,请在列定义中设置以下内容:

"bUseRendered": false

这将使表格对数据进行排序,而不是对渲染的输出进行排序。

Since you're showing a link, I'm guessing you're using a custom render function?

If that's the case, in your column definition set the following:

"bUseRendered": false

That'll make the table sort on the data, and not the rendered output.

更多推荐

本文发布于:2023-08-07 18:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   datatables   jquery   properly   sorting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!