我有我需要应用排序表。 我使用的基因敲除和jquery.tablesorter.js。 我曾试图自定义绑定,但也没有帮助。 没有击倒我的代码工作正常。 下面是我的表。
<table class="tbl" id="dash" data-bind="sortTable: true">
<thead>
<tr class="tag close">
<th>Type</th>
<th>Title</th>
</tr>
</thead>
<tbody class="scrollContent" data-bind="foreach: Course">
<tr>
<td><i class="icon"></i></td>
<td><a href="#" id="qtipselector_01" data-bind="text: Title"></a></td>
<div id="TooltipContent_01" class="hidden">
<a> Test Tool Tip</a>
</div>
</div>
</tr>
</tbody>
</table>
下面是一个例子: http://jsfiddle.net/jearles/RGsEH/
注:JS和CSS文件依赖性正在管理的资源带来英寸
HTML
<table data-bind="sortTable: true">
<thead>
<tr>
<th>Type</th>
<th>Title</th>
</tr>
</thead>
<tbody data-bind="foreach: course">
<tr>
<td data-bind="text: type"></td>
<td data-bind="text: title"></td>
</tr>
</tbody>
</table>
JS
function Course(type, title) {
this.type = type;
this.title = title;
}
var ViewModel = function() {
this.course = ko.observableArray([
new Course("type", "course1"),
new Course("another_type", "course2"),
new Course("second_type", "course5"),
new Course("third_type", "course4"),
new Course("fourth_type", "course3")
]);
}
ko.bindingHandlers.sortTable = {
init: function(element, valueAccessor) {
setTimeout( function() {
$(element).addClass('tablesorter');
$(element).tablesorter({widgets: ['zebra']});
}, 0);
}
};
ko.applyBindings(new ViewModel());
通过@约翰Earles上述解决方案适用于预先定义的数据表,但是当我们将动态数据表,但它有点打破。
请检查: http://jsfiddle.net/vkctata/vdcox07c/1/
function Course(type, title) {
this.type = type;
this.title = title;
}
var ViewModel = function() {
this.addNewItem = function() {
this.course.push(new Course("nth_type", "course33"));
return false;
}
this.course = ko.observableArray([
new Course("type", "course1"),
new Course("another_type", "course2"),
new Course("second_type", "course5"),
new Course("third_type", "course4"),
new Course("fourth_type", "course3")
]);
}
ko.bindingHandlers.sortTable = {
init: function(element, valueAccessor) {
setTimeout(function() {
$(element).addClass('tablesorter');
$(element).tablesorter({
widgets: ['zebra']
});
}, 0);
}
};
ko.applyBindings(new ViewModel());
我们找到了一种方法来创造了近通用的排序,请点击此链接淘汰赛排序