无法在 ext.net 网格面板内的组合框中检索和设置值
Posted
技术标签:
【中文标题】无法在 ext.net 网格面板内的组合框中检索和设置值【英文标题】:Can't retrieve and set a value in combobox inside ext.net gridpanel 【发布时间】:2015-05-21 19:28:16 【问题描述】:我在 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】:将绑定监听器添加到 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>
【讨论】:
嗨鲍里斯!它对我帮助很大。谢谢,现在值是绑定的,但是当我在组合框中选择其他选项时,它仍然没有改变值。当我同步时,发送的值永远是“NA”。选择其他选项时需要添加其他侦听器来更改值吗? 我改变了我的答案。请不要记得将更新行为添加到存储 一切正常。谢谢鲍里斯。以上是关于无法在 ext.net 网格面板内的组合框中检索和设置值的主要内容,如果未能解决你的问题,请参考以下文章
当关联的数据库值在 int-Ext.Net 中时,如何在网格面板列中显示文本(字符串)?