【问题标题】:ExtJS Checkcolumn not rendering checked valuesExtJS Checkcolumn 未呈现检查值
【发布时间】:2017-10-07 15:36:26
【问题描述】:

我有一个名为"Schema"tab,它会呈现一个grid。其中一个网格列是checkcolumn 类型。 渲染网格时我应该将什么值传递给商店,所以我选中了一些复选框而没有选中其他复选框?这一定是非常琐碎的事情,但我找不到解决方案所以远的。

这是网格和校验列的简化结构:

{
title: 'Schema',
listeners: {
    activate: function(tab) {
        myNmsps.renderSchema();
    }
},
id: 'schemaTab',
items: [{
    xtype: 'grid',
    id: 'schema',
    border: false,
    data: [],
    columns: [
        {
            text: 'Name',
            dataIndex: 'name',
            editor: {
                xtype: 'textfield',
                isEditable: true,
            }
        },{
            text: 'Position',
            dataIndex: 'position',
            editor: {
                xtype: 'combobox',
                id: 'position',
            }
        }, {
            text: 'Type',
            dataIndex: 'type',
            id: "TypeDropdown",
            editor: {
                xtype: 'combobox',
                id: 'SelectType',
            }
        }, {
            text: 'Size',
            dataIndex: 'size',
            id: "SizeDropdown",
            editor: {
                xtype: 'combobox',
                id: 'SelectSize',
            }
        }, {
            text: 'FilteringType',
            dataIndex: 'filteringType',
            editor: {
                xtype: 'combobox',
                id: 'filteringType',
            }
        },  {
            xtype:'checkcolumn',
            fieldLabel: 'checkboxIsUnique',
            name: 'checkboxIsUnique',
            text: 'Is Unique',
            id: 'checkboxIsUniqueID',
            dataIndex : 'checkboxIsUniqueIDX',
            listeners:{
                checkchange: function(column, rowIdx, checked, eOpts){
                    var schemaStore = Ext.getCmp('schema').getStore();
                    schemaStore.each(function(record,idx){
                        if(rowIdx == idx && checked===true){
                            record.set('checkboxIsUnique',true);
                            record.raw[6] = true;
                        } else if(rowIdx == idx && checked===false){
                            record.set('checkboxIsUnique',false);
                            record.raw[6] = false;
                        }
                        record.commit();
                    }); 
                }
            }
        },
        {
            text: 'Delete',
            dataIndex: 'deleteColumn',
            id: "deleteColumn"
        }
    ],
    listeners: {
    },
    plugins: [
        Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 2
        })
    ]
}

checkchange监听器中

这是生成存储和渲染网格的简化函数:

renderSchema: function() {
    var grid = Ext.getCmp("schema");

    for (var i = 0; i < myGridData; i++) {
        storeArr[i][0] = myGridData[i].name;
        storeArr[i][1] = myGridData[i].type;
        storeArr[i][2] = myGridData[i].size;
        storeArr[i][3] = i;
        storeArr[i][4] = "<button class='schemaDeleteButton x-btn'> </button>";
        storeArr[i][5] = myGridData[i].filteringType;
        storeArr[i][6] = myGridData[i].isUnique; // true/false;
    }

    var dataStore = Ext.create('Ext.data.ArrayStore', {
        extend: 'Ext.data.Model',
        fields: [
           {name: 'name'}, 
           {name: 'type'}, 
           {name: 'size'}, 
           {name: 'position'}, 
           {name: 'deleteColumn'},
           {name: 'filteringType'},
           {name: 'checkboxIsUnique'}
        ],
        data: storeArr
    });

    grid.suspendEvents();
    grid.reconfigure(dataStore);
    grid.resumeEvents();
}

所以我为字段checkboxIsUnique 传递真或假,但这不会影响我的界面,如下所示:

【问题讨论】:

  • 您的 dataIndexcheckboxIsUniqueIDX,但您没有填充它。
  • @EvanTrimboli 我试过了,但没用。现在当你说它时,我意识到我也应该在checkchange 监听器中设置它。我在两个地方(renderSchema 函数和 checkchange 侦听器)都使用了dataIndex,现在它可以工作了!谢谢你。如果你愿意 - 把它写成答案,我会接受。

标签: javascript extjs checkbox grid


【解决方案1】:

renderSchema 函数中 dataStore 中的字段应该命名为 'checkboxIsUniqueIDX' - 与 checkcolumn 组件中的 dataIndex 相同。

【讨论】:

    猜你喜欢
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多