How to work with Jquery Table Sorter with knockout

后端 未结 2 446
野性不改
野性不改 2021-01-02 17:00

I have a table on which i need to apply sorting. I\'m using knockout and jquery.tablesorter.js. I have tried custom binding also but is not helping. Without knockout my code

2条回答
  •  余生分开走
    2021-01-02 17:13

    Here is an example: http://jsfiddle.net/jearles/RGsEH/

    NOTE: The JS and CSS file dependencies are brought in under Managed Resources.

    HTML

    Type Title

    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());
    

提交回复
热议问题