0

*已解决,请参阅下面的评论*

我正在尝试通过在 slickgrid http://mleibman.github.io/SlickGrid/examples/example-checkbox-row-select.html中遵循此示例来实现复选框行选择模型,但它不起作用。

当我在我的应用程序中尝试它时,我得到的只是标题单元格中的一个复选框,但所有行都有一个“...”(值未定义)。

有人可以帮忙吗?

这是我的代码:

 var EntityGrid = function ($container, el, columns, collection, filterFields, isUnmappable, source) {

    var options = {
        enableCellNavigation:true,
        enableColumnReorder:false,
       // forceFitColumns:true,
        enableTextSelectionOnCells:true,
        rowHeight: 28
    };

    var checkboxSelector = new Slick.CheckboxSelectColumn({
        cssClass: "slick-cell-checkboxsel"
    });

    this.isUnmappable = isUnmappable;
    this.source = source;
    columns = this.prepareColumns(columns, checkboxSelector);
    this.collection = collection;
    this.$container = $container;
    this.dataView = new Slick.Data.DataView();
    this.grid = new Slick.Grid(el, this.dataView, columns, options);
    this.grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: false}));
    this.grid.registerPlugin(checkboxSelector);
    this.filterFields = filterFields;
    this.setupGridEvents();
    this.setupFilter();
    this.grid.render();
    var columnpicker = new Slick.Controls.ColumnPicker(columns, this.grid, options);
    return this;
};

EntityGrid.prototype = {

    prepareColumns:function (columns, checkboxSelector) {
        var self = this;
        columns.push(checkboxSelector.getColumnDefinition());
        _.each(columns, function (item) {
            if (item.type === "link") {
                item.formatter = self.linkFormatter;
            } else if (item.type === "editableBoolean") {
                item.formatter = self.checkboxFormatter;
            } else {
                item.formatter = self.defaultFormatter;
            }
        });
... other columns definations
4

1 回答 1

0

我所做的只是阻止我的默认格式化程序应用于复选框选择列。

我在 _.each 循环中添加了一个条件,如下所示:

_.each(columns, function (item) {
        if(item.cssClass !== "slick-cell-checkboxsel") {
            if (item.type === "link") {
                item.formatter = self.linkFormatter;
            } else if (item.type === "editableBoolean") {
                item.formatter = self.checkboxFormatter;
            } else {
                item.formatter = self.defaultFormatter;
            }
        }
    });
于 2013-07-18T08:37:17.573 回答