是这样的,我有一个数据库表,其中一个字段(假设字段名称为a)用来表示这行数据是否有效。现在我要把这个表的数据用Grid来显示,但是我想让a这个字段的值显示为一个checkbox,选中代表有效,没选中的代表无效,这样方便用户操作更改。
   请问该怎么实现?我用的是4.1.1版本

解决方案 »

  1.   

    先把后台a字段的值赋给一个隐藏列,然后加载完后把grid每行遍历一下,根据每行的隐藏列的值来判断是否要把这行的checkbox选中
      

  2.   

    但是我希望能通过点击checkbox来实现对字段a的值的更改,比如没选中的时候我选中checkbox就能把a字段的值变成有效
      

  3.   

    不是有个renderer配置,
    columns: [{
                text: '状态',
                sortable: false,
                dataIndex: 'state',//数据源中的状态列
                renderer: function (v) { return '<input type="checkbox"'+(v=="1"?" checked":"")+'/>'; }//根据值返回checkbox是否勾选
            }至于更新你可以直接给checkbox增加onclick事件每次click更新或者最后遍历checkbox状态得到勾选和取消的状态一起提交到服务器更新
      

  4.   

    extjs4里有grid checkbox的插件叫 CheckboxModel也许可以满足你的需求
     var sm = Ext.create('Ext.selection.CheckboxModel');
        var grid2 = Ext.create('Ext.grid.Panel', {
            store: getLocalStore(),
            selModel: sm,
            columns: [
                {text: "Company", width: 200, dataIndex: 'company'},
                {text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
                {text: "Change", dataIndex: 'change'},
                {text: "% Change", dataIndex: 'pctChange'},
                {text: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
            ],
            columnLines: true,
            width: 600,
            height: 300,
            frame: true,
            title: 'Framed with Checkbox Selection and Horizontal Scrolling',
            iconCls: 'icon-grid',
            renderTo: Ext.getBody()
        });
      

  5.   

    你的这个方法我试过了,这个是在每一行之前加一个checkbox用来选中这一行,我想要在每一行的一个字段中不显示数据而是一个checkbox,这个checkbox根据数据来决定是否是选中的。