gpt4 book ai didi

javascript - JQuery DataTables 土耳其语字符排序问题

转载 作者:行者123 更新时间:2023-11-28 04:50:15 24 4
gpt4 key购买 nike

我有一个数据,其中一些以土耳其字符开头。当我对它们进行排序时,它们将成为最后的记录。我尝试使用 turkish-string插件但它给出了一个错误。

Uncaught TypeError: Cannot read property 'mData' of undefined
at HTMLTableCellElement. (jquery.dataTables.js:1197)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at HTMLTableElement. (jquery.dataTables.js:1194)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.DataTable [as dataTable] (jquery.dataTables.js:869)
at n.fn.init.$.fn.DataTable (jquery.dataTables.js:15104)
at HTMLDocument. (jquery-datatable.js:25)
at i (jquery.min.js:2)

您可以在下面找到代码:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"turkish-pre": function ( a ) {
var special_letters = {
"C": "Ca", "c": "ca", "Ç": "Cb", "ç": "cb",
"G": "Ga", "g": "ga", "Ğ": "Gb", "ğ": "gb",
"I": "Ia", "ı": "ia", "İ": "Ib", "i": "ib",
"O": "Oa", "o": "oa", "Ö": "Ob", "ö": "ob",
"S": "Sa", "s": "sa", "Ş": "Sb", "ş": "sb",
"U": "Ua", "u": "ua", "Ü": "Ub", "ü": "ub"
};
for (var val in special_letters)
a = a.split(val).join(special_letters[val]).toLowerCase();
return a;
},

"turkish-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"turkish-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );

$('#dataTable').dataTable({
'aoColumns' : [
{'sType' : 'turkish'}
]
});

最佳答案

确保在加载数据表之前调用扩展函数

// extended function for turkish characters---------------------------
$.extend($.fn.dataTableExt.oSort, {
"turkish-pre": function (a) {
var special_letters = {
"C": "Ca", "c": "ca", "Ç": "Cb", "ç": "cb",
"G": "Ga", "g": "ga", "Ğ": "Gb", "ğ": "gb",
"I": "Ia", "ı": "ia", "İ": "Ib", "i": "ib",
"O": "Oa", "o": "oa", "Ö": "Ob", "ö": "ob",
"S": "Sa", "s": "sa", "Ş": "Sb", "ş": "sb",
"U": "Ua", "u": "ua", "Ü": "Ub", "ü": "ub"
};
for (var val in special_letters)
a = a.split(val).join(special_letters[val]).toLowerCase();
return a;
},

"turkish-asc": function (a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"turkish-desc": function (a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});

// your data table-----------------------------------------
var dataSet1 = [
['A ', 'A '],
['Ğ ', 'B'],
['Z', 'C'],
['Ç', 'B']

];
$('#datatable-table').dataTable({
'aoColumns': [
{ 'sType': 'turkish' },
{ 'sType': 'string' }
],
"destroy": true, //To delete previous DataTable instance
"data": dataSet1, //Link the dataset
"iDisplayLength": 10, //Number of dataitems in one page
"bLengthChange": false, //Change this to 'true', to choose number of items per page
"columns": [ // Table column names
{ "title": "Student Name" },
{ "title": "Student Grade" }
],
});

Working Plunker

关于javascript - JQuery DataTables 土耳其语字符排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com