我在jQuery数据表中添加了下拉选项。
table.columns().every(function() {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.footer()).empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function(value, j) {
select.append('<option value="' + value + '">' + value + '</option>')
});
});
以下是完整的源代码 plunker link
当我打开下拉列表时,值被排序为String而不是整数。 例如,这里的下拉列表给出了选择
[1,10,11,2,...] && [Item 1,Item 10,Item 11,...]
我想要回答
[1,2,3,4,..10,11..] && [Item 1,Item 2,Item 3,...]
答案 0 :(得分:0)
您可以使用Sorting plugins
执行此操作像这样修改你的代码:
let label = UILabel()
label.frame = CGRect(x: 120, y: 100, width: 200, height: 30)
let first = "first"
let second = "second"
let third = "third"
let stringValue = "\(first)\(second)\(third)" // or direct assign single string value like "firstsecondthird"
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: stringValue)
attributedString.setColorForText(textToFind: first, withColor: UIColor.red) // use variable for string "first"
attributedString.setColorForText(textToFind: "second", withColor: UIColor.green) // or direct string like this "second"
attributedString.setColorForText(textToFind: third, withColor: UIColor.blue)
label.font = UIFont.systemFont(ofSize: 26)
label.attributedText = attributedString
self.view.addSubview(label)
结果可以在这里看到:https://plnkr.co/edit/MJgKWrYpFmmr0v43hKd4?p=preview