无法在ext.net gridpanel内的combobox中检索和设置值

时间:2015-05-21 19:28:17

标签: extjs combobox ext.net gridpanel

我在ext.net网格面板中遇到了很多关于组合框的问题。我插入新记录时需要设置默认值。其实我这样做:

Javascript代码:

function insertRecordTestesVerif(grid) {
            var store = grid.store,
                row = store.indexOf(store.insert(0, {
                    Hora: new Date(),
                    n_saco: 0,
                    solda_status : "NA",
                    peso: 0,
                    peso_status: "NA",
                    detector_metais: "NA",
                    impressora: "NA",
                    cola: "NA",
                    qualidade: "NA",
                })[0]);

            Ext.defer(function () {
                grid.editingPlugin.startEditByPosition({ row: row, column: 0 });
            }, 100);
        }

我的组合框就像这样:

<ext:ComponentColumn
                                        runat="server"
                                        Text="Status"
                                        DataIndex="peso_status"
                                        Flex="1">
                                        <Component>
                                            <ext:ComboBox runat="server" Editable="false">
                                                <Items>
                                                    <ext:ListItem Text="NA" Value="NA" />
                                                    <ext:ListItem Text="OK" Value="OK" />
                                                    <ext:ListItem Text="NC" Value="NC" />
                                                </Items>
                                            </ext:ComboBox>
                                        </Component>
                                    </ext:ComponentColumn>

好吧,我设置的值'不是'在组合框中默认显示,当我同步网格时,发送的值永远是“NA”。

欢迎任何帮助。谢谢大家。

1 个答案:

答案 0 :(得分:0)

将Bind侦听器添加到ComponentColumn。看看这个例子:

<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" />
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            this.Store1.DataSource = this.Data;
            this.Store1.DataBind();
        }
    }

    private object[] Data
    {
        get
        {
            return new object[]
            {
                new object[] { 1, "OK"},
                new object[] { 2, "NC"},
                new object[] { 3, "NA"},
                new object[] { 4, "NC"},
                new object[] { 5, "OK"},
                new object[] { 6, "NC"}
            };
        }
    }   
    </script>
    <ext:GridPanel ID="Grid1" runat="server" Width="400" Height="300">
        <Store>
            <ext:Store ID="Store1" runat="server">
                <Model>
                    <ext:Model runat="server" IDProperty="id">
                        <Fields>
                            <ext:ModelField Name="id" Type="Int" />
                            <ext:ModelField Name="peso_status" />
                        </Fields>
                    </ext:Model>
                </Model>
                <Reader>
                    <ext:ArrayReader IDProperty="id" />
                </Reader>
            </ext:Store>
        </Store>
        <ColumnModel runat="server">
            <Columns>
                <ext:Column runat="server" DataIndex="id" />
                <ext:ComponentColumn runat="server" Text="Status" DataIndex="peso_status" Flex="1">
                    <Component>
                        <ext:ComboBox runat="server" Editable="false">
                            <Items>
                                <ext:ListItem Text="NA" Value="NA" />
                                <ext:ListItem Text="OK" Value="OK" />
                                <ext:ListItem Text="NC" Value="NC" />
                            </Items>
                        </ext:ComboBox>
                    </Component>
                    <Listeners>
                        <Bind Handler="
                            cmp.setValue(record.get('peso_status'));
                            if(!cmp.keyValue){
                                cmp.keyValue = record.get('id');
                                cmp.on('change',function(item,newValue,oldValue){
                                    var rec = #{Store1}.getAt(#{Store1}.findExact('id',item.keyValue));
                                    Ext.defer(function() {
                                        rec.set('peso_status', newValue);
                                        #{Store1}.sync();
                                    }, 10);
                                });
                            }
                            " />
                    </Listeners>
                </ext:ComponentColumn>
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
</body>
</html>