KnockoutJs KoGrid 无法勾选复选框以供选择

KnockoutJs KoGrid unable to tick checkbox for selection

我有一个 KnockoutJs Ko Grid,它被配置为允许用户 select 多行。行可以被 selected,我能够确定在绑定到按钮点击的 JS 函数中哪些行被 selected。但是,显示不太正确。当用户单击网格左侧的复选框时,它不会被选中。

在我的 JS 视图模型中,我设置了以下 gridOptions。我已将 selectedwithCheckboxOnly 设置为 true 因为其中一列包含我需要用户能够操作的超链接:

this.gridOptions = {
    data: self.myData,
    enablePaging: true,
    pagingOptions: self.pagingOptions,
    filterOptions: self.filterOptions,
    selectWithCheckboxOnly: true,
    selectedItems: self.selected,
    canSelectRows: true,
    displaySelectionCheckbox: true,
    columnDefs: [{ field: 'Timestamp', displayName: 'Timestamp', width: 130 },
                { field: 'State', displayName: 'State', width: 70 },
                { field: 'FaultApplication', displayName: 'Application', width: 110 },
                { field: 'FaultExceptionMessage', displayName: 'Exception Message', width: 400 },
                { field: 'FaultServiceName', displayName: 'ServiceName', width: 140 },
                { field: 'LinkToFaultsPage', displayName: 'Link to Fault', width: 80, cellTemplate: '<a data-bind="attr: { href: $parent.entity.LinkToFaultsPage}" >Fault</a>' }
    ]
};

我在以下 JsFiddle 中发现了相同的行为:http://jsfiddle.net/BizTalkers/oowgbj80/

这似乎是一个已知错误,已被 GitHub 用户 ricred and kiaplayer here 解决。

kogrid 未正确更新复选框绑定到的选定状态。如果您通过数据绑定添加自定义 afterSelectionChange 方法,您将解决问题。将 fiddle 中的 HTML 更新为:

<div id="wrapper" data-bind="koGrid:{data:myObsArray, afterSelectionChange: function () { return true; } }"></div>

(example)