我想我知道这个问题,但我不知道如何正确处理它,所以我希望这里有人有类似的问题,并设法解决它的方式。 我所拥有的是一个包含几列的表,除了一个列之外,所有这些列都可以进行排序。 下面是该列的屏幕截图及其在工作中的排序。
正如您所看到的那样,它不会根据字母数字逻辑进行排序。 我的假设是某些名称中包含逗号括号,括号等字符。 所以说,我将如何处理这个问题,以便我可以使用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": falseThat'll make the table sort on the data, and not the rendered output.
更多推荐
发布评论