【问题标题】:Checking rows in extjs grid based on their state根据状态检查 extjs 网格中的行
【发布时间】:2018-07-26 08:45:30
【问题描述】:

我目前正在做一个使用 ExtJS 的项目。

对于项目的这一部分,我必须在现有网格上实现 复选框列网格的每一行都可以具有由 record.data.codiceStato 确定的状态。强>

这是部分代码:

selectionModel = Ext.create('Ext.selection.CheckboxModel', {
    checkOnly: true,
    listeners: {
        select: function (sm, idx, rec) {
            alert("Look ma!")
        }
    },
    renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
        if (record.data.codiceStato == 'RS' || record.data.codiceStato == 'AN' || record.data.codiceStato == 'NP')
            return '<div style="margin-left: -1px;" class="' + Ext.baseCSSPrefix + 'grid-row-checker"> </div>';
        else
            return '';
    }
});

现在,如您所见,我仅在具有精确状态(RS、AN、NP)的特定行上呈现复选框。我的问题是,当我单击标题复选框网格中的所有行都被选中时,那些不处于应该能够被选中的状态的行(状态不同于 NP RS AN )。有没有什么办法解决这一问题?先感谢您。

【问题讨论】:

  • 未测试,但如果记录不是您允许的状态之一,您不能使用 beforeselect 事件中的 return false 吗?
  • @MattAllwood 实际工作!唯一的问题:它也禁用了标题复选框。这是我使用的条件: if(idx.data.codiceStato != 'RS' && idx.data.codiceStato != 'AN' && idx.data.codiceStato != 'NP') return false;
  • 您将不得不修改并覆盖设置网格标题的代码。我会看看Ext.selection.CheckboxModel.updateHeaderState - 如果 selectableCount === selectedCount,你需要让 hdSelectStatus 为真。请注意,这种代码是升级时容易损坏的东西,因此您需要密切关注它

标签: checkbox extjs grid extjs4.1


【解决方案1】:

可以使用rowIndex 检测标题复选框。

if (rowIndex != 0) {
    if (record.data.codiceStato == 'RS' || record.data.codiceStato == 'AN' || record.data.codiceStato == 'NP') {
        return '<div style="margin-left: -1px;" class="' + Ext.baseCSSPrefix + 'grid-row-checker"> </div>';
    }
    else {
        return '';
    }
}
else {
    return '';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    相关资源
    最近更新 更多