1

我可以通过添加硬编码索引值来设置静态行或列索引,但是如果用户想要选择列,我们如何使用淘汰赛js来做到这一点。目前我已经设置了静态列索引,但我希望用户能够选择要冻结的列。

var viewModel= function () {
        var self = this;           
        self.data = ko.observableArray([]);            
        self.recordCount = ko.observable(0);
        self.lowTotNoOfRec = ko.observable(0);
        self.pageSize = ko.observable(10);
        self.pageIndex = ko.observable(0);          
        self.paged = function (e, data) {
            self.pageIndex(data.newPageIndex);
        };
        self.staticColumnIndex = -1;

}。

4

1 回答 1

2

Assuming you created a custom binding handler to set up your grid:

<table data-bind="wijgrid:gridConfig"></table>

And your gridConfig includes an observable for staticColumnIndex:

self.gridConfig = {
    //...other configuration stuff...
    staticColumnIndex: ko.observable(-1)
};

Then the init of the custom binding handler can subscribe to changes on staticColumnIndex and update the value for the grid:

ko.bindingHandlers.wijgrid = {
    init: function (element, valueAccessor, allBindingsAccessor, data, context) {
        var options = valueAccessor() || {};
        var grid = $(element).wijgrid({
            cellClicked: function (e, args) {
                alert(args.cell.value());
            },
            allowPaging: true,
            pageSize: options.pageSize(),
            data: options.data(),
            columns: options.headers,
            scrollMode: "auto"
        });
        options.staticColumnIndex.subscribe(function (newValue) {
            grid.wijgrid({
                staticColumnIndex: newValue
            });
        });
    }
};

Demo: http://jsfiddle.net/pvo4mk3c/

PS: It looks like once you have a freeze column indicator on the graph, you can drag it back and forth. The observable is not affected by those changes in my demo.

于 2015-06-22T16:12:24.230 回答