默认情况下,将gridpanel复选框设为只读

时间:2017-03-24 10:08:39

标签: extjs

我有一个包含少量项目和复选框的网格面板。我希望默认情况下检查和读取网格面板中的特定项目(用户不能更改选中的值)。我该怎么做?我的代码如下:

 var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
        mode : 'SIMPLE',
        listeners : {
            selectionchange : function(selectionModel) {
            }
        },

    });

var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
        storeId: 'userCheckboxStore',
        fields: ['data'],
        data: [
            { data: 'Item 1'},
            { data: 'Item 2' },
            { data: 'Item 3'},
            { data: 'Item 4'},
            { data: 'Item 5'},

        ]
    });

var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
        layout : {
            type : 'vbox',
            align : 'stretch'
        },
        defaults : {
            border : 0,
            bodyStyle : {
                backgroundColor : 'transparent'
            }
        },
        store: CheckboxContainersStore, 
        selModel: MyCheckboxModel,
        title: 'Item List',
        columns: [
            { dataIndex: 'data'},
        ]
    });

我想要'项目1'默认情况下检查和只读。任何建议将不胜感激

2 个答案:

答案 0 :(得分:2)

您需要这样的内容,here you can try a fiddle

您无法使用readonly true,但您可以选择网格,并确保item1永远不会被取消选择。

Options

答案 1 :(得分:1)

另一种实施方式就是这样。

var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
  mode: 'SIMPLE',
  checkOnly: true,
  listeners: {
    beforedeselect: function(grid, record, index, eOpts) {
      if (record.get('data') == "Item 1") {
        return false;
      }
    }
  }
});

var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
  storeId: 'userCheckboxStore',
  fields: ['data'],
  data: [{
      data: 'Item 1'
    }, {
      data: 'Item 2'
    }, {
      data: 'Item 3'
    }, {
      data: 'Item 4'
    }, {
      data: 'Item 5'
    },

  ]
});

var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
  layout: {
    type: 'vbox',
    align: 'stretch'
  },
  defaults: {
    border: 0,
    bodyStyle: {
      backgroundColor: 'transparent'
    }
  },
  listeners: {
    'viewready': function(grid) {
      grid.selModel.doSelect(grid.store.data.items[0]);
    }
  },
  store: userCheckboxContainersStore,
  selModel: MyCheckboxModel,
  title: 'Item List',
  columns: [{
    dataIndex: 'data'
  }],
  renderTo: Ext.getBody()
});

更新小提琴:http://jsfiddle.net/y61yo7sx/1/