在网格组合框中使用自定义 HTML

发布于 2024-12-07 19:02:33 字数 229 浏览 0 评论 0原文

我需要设置网格在线编辑组合框来显示自定义 HTML。为了更具体,请查看此示例。单击Light列中的任意单元格,打开组合框。我想在每个选项(“阴影”,“大部分阴影”,...)附近放置具有独特颜色的方框。

I need to set up grid enline-editing combo box to show custom HTML. To be more concrete, please, look at this sample. Click any cell in Light column, open combobox. I want to place near every option ("Shade", "Mostly shady", ...) square box with unique color.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最舍不得你 2024-12-14 19:02:33

我也遇到了同样的问题。当我尝试上面的解决方案时终于找到了答案(它也不起作用,但非常接近)。

结果列表项的类是 x-boundlist-item 而不是 x-combo-list-item。

如果您用该类标记您的 div 它将起作用。非常令人沮丧的是,Sencha 文档中组合框的 tpl 配置项下没有概述这一点,特别是当我能找到的所有示例都只显示项目的简单 div 时。我猜它曾经通过用 li 和类包装 tpl 配置中的任何内容来工作,但现在不再这样了。也就是说,这更通用,因为您可以通过省略这些项目的类来制作在下拉列表中不可选择的标题和行。

var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
    data : [
        {"abbr":"AL", "name":"Alabama"},
        {"abbr":"AK", "name":"Alaska"},
        {"abbr":"AZ", "name":"Arizona"}
        //...
    ]
});


Ext.application({
    name: 'SRC',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            xtype:{
                type:'vbox',
                align: 'center',
                pack: 'center'
            },   items:[
                     {xtype:'combobox',
                      fieldLabel: 'Choose State',
                      store: states,
                      queryMode: 'local',
                      displayField: 'name',
                      valueField: 'abbr',
                      tpl:'<tpl for="."><div class="x-boundlist-item">{name}</div></tpl>'

                            }

        ]})
}})

谢谢

I was having the same problem. Finally found the answer when I was trying the solution above (which doesn't work either but is really close).

Turns out that the class for the list items is x-boundlist-item not x-combo-list-item.

If you mark your div with that class it will work. Extremely frustrating that this isn't outlined in the Sencha docs under the tpl config item for combo boxes, especially when all of the examples I can find just show a simple div for the items. I'm guessing it used to work by wrapping whatever was in the tpl config with the li and the class but it doesn't anymore. That said this is more versatile since you can make headers and lines that aren't selectable in your dropdowns by leaving off the class for those items.

var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
    data : [
        {"abbr":"AL", "name":"Alabama"},
        {"abbr":"AK", "name":"Alaska"},
        {"abbr":"AZ", "name":"Arizona"}
        //...
    ]
});


Ext.application({
    name: 'SRC',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            xtype:{
                type:'vbox',
                align: 'center',
                pack: 'center'
            },   items:[
                     {xtype:'combobox',
                      fieldLabel: 'Choose State',
                      store: states,
                      queryMode: 'local',
                      displayField: 'name',
                      valueField: 'abbr',
                      tpl:'<tpl for="."><div class="x-boundlist-item">{name}</div></tpl>'

                            }

        ]})
}})

Thanks

旧夏天 2024-12-14 19:02:33

为了使其全局工作(对于所有组合框),请使用以下覆盖:

Ext.override(Ext.form.field.ComboBox, {
  initComponent: function() {

    // the code above remains same (you can copy it from ext-all-debug.js), add the following at the end of initComponent
    me.tpl = new Ext.XTemplate(
            '<tpl for=".">',
                '<div class="x-boundlist-item">',
                    '{' + me.displayField + ':htmlEncode}',
                '</div>',
            '</tpl>'
        );
   }
});

For making it work globally (for all comboboxes), use the following override:

Ext.override(Ext.form.field.ComboBox, {
  initComponent: function() {

    // the code above remains same (you can copy it from ext-all-debug.js), add the following at the end of initComponent
    me.tpl = new Ext.XTemplate(
            '<tpl for=".">',
                '<div class="x-boundlist-item">',
                    '{' + me.displayField + ':htmlEncode}',
                '</div>',
            '</tpl>'
        );
   }
});
暮凉 2024-12-14 19:02:33

您需要做的只是修改 ComboBoxtpl 配置选项,并使用您自己的自定义配置。然后,您可以创建一个新的 ComboBox 并将其用作列定义的编辑器

以下是自定义 ComboBox 模板的示例:

var resultTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div class="x-combo-list-item">',
        '<span class="number">{#}</span>',            
            '<h3 class="{itemColor"}>',
                '{itemName}',
            '</h3>',
        '</div>',
    '</tpl>'
);

然后,您可以在实例化编辑器时使用该 XTemlate;

var combo = {
    xtype: 'combo',
    tpl: resultTpl
    ....
}

What you need to do is just modify the tpl config option of the ComboBox, and use your own custom config. You can then create a new ComboBox and use that as the editor for the column definition.

Here's a sample of a custom ComboBox template:

var resultTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div class="x-combo-list-item">',
        '<span class="number">{#}</span>',            
            '<h3 class="{itemColor"}>',
                '{itemName}',
            '</h3>',
        '</div>',
    '</tpl>'
);

You can then use that XTemlate when you instantiate your editor;

var combo = {
    xtype: 'combo',
    tpl: resultTpl
    ....
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文