Slickgrid复选框行选择不起作用

时间:2013-06-24 10:55:51

标签: javascript slickgrid

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

我正在尝试通过在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

1 个答案:

答案 0 :(得分: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;
            }
        }
    });
相关问题