我在使用智能表对数据进行排序时遇到问题,特别是在包含 土耳其字符 时。生成错误的订单。
在我的控制器中:
$scope.rowCollection = [{
a: 'Çanakkale',
b: '3'
}, {
a: 'Ceyhan',
b: '2'
}, {
a: 'ĞĞĞĞĞ',
b: '4'
}, {
a: 'Ankara',
b: '1'
}, {
a: 'Zonguldak',
b: '5'
}];
$scope.displayedCollection = [].concat($scope.rowCollection);
和我的HTML:
<tr ng-repeat="row in displayedCollection">
<td ng-repeat="col in columns">{{row[col]}}</td>
</tr>
这里是插件:
http://plnkr.co/edit/JW4G1n2QszIqYjcAmlNz
我该如何解决?
感谢您的帮助
答案 0 :(得分:0)
这是我为你找到的:
st-set-sort="yourFilterName"
,st-table
属性为:
<table st-table="displayedCollection" st-set-sort="turkishFilter" st-safe-src="rowCollection" class="table table-striped">
angular.module('myApp', ['smart-table'])
.filter('turkishFilter', function(){
return function(items, field, isDescending){
//If you don't create a copy of the array,
//smart-table won't be able to restore the natural order state
var result = items.slice();
//Working only for string properties ATM!
result.sort(function(first, second){
//return first.a.localeCompare(second.a, 'tr');
//OR
return first[field].localeCompare(second[field], 'tr');
//localCompare() is supported only in IE11 and upwards
});
if (isDescending){
result.reverse();
}
return result;
};
})
工作插件HERE