• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    extjs中grid中嵌入动态combobox的应用

    发布者: 福建二哥 | 发布时间: 2025-8-13 12:43| 查看数: 94| 评论数: 0|帖子模式

    拿combobox的数据

    comboDS = new Ext.data.JsonStore({
    url : 'test.do',
    fields : [{
    name : 'id'
    }, {
    name : 'display'
    }]
    });

    combobox定义
    combobox 中的id必须要有,后面要跟据id取combobox值。

    var comboBox = new Ext.form.ComboBox({
    id : "cb", //必须有
    typeAhead : true,
    readOnly : true,
    allowBlank : false,
    autoScroll : true,
    selectOnFocus : true,
    emptyText : '请选择...',
    store : comboDS,
    forceSelection : true,
    triggerAction : 'all',
    displayField : 'display',
    valueField : 'id'
    });

    grid 的定义:

    ds = new Ext.data.Store({
    baseparams : {
    start : 0,
    limit : RowCount
    },
    proxy : new Ext.data.HttpProxy({
    url :'test2.do'
    }),
    reader : new Ext.data.JsonReader({
    root : 'data',
    totalProperty : 'totalCount'
    }, [{
    name : "bh"
    }, {
    name : "test"
    }]);
    });
    var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
    header : "编号",
    dataIndex : "bh"
    }, {
    header : "测试",
    dataIndex : "test",
    renderer : renderer,
    editor : comboBox
    }]);
    grid = new Ext.grid.EditorGridPanel({
    title : '测试',
    ds : ds,
    cm : cm,
    clicksToEdit : 1,
    viewConfig : {
    forceFit : true
    },
    bbar : new Ext.PagingToolbar({
    pageSize : RowCount,
    store : ds,
    displayInfo : true,
    displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
    emptyMsg : "没有记录"
    })
    });

    cm 的renderer函数
    此方法为解决combobox修改后显示为id

    function renderer(value, p, r) {
    var index = comboDS.find(Ext.getCmp('cb').valueField, value);
    var record = comboDS.getAt(index);
    var displayText = "";
    if (record == null) {
    displayText = value;
    } else {
    displayText = record.data.display;// 获取record中的数据集中的display字段的值
    }

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表