PDA

View Full Version : [CLOSED] how to dynamic add one column to the gridpanel?



tobros
Jul 22, 2013, 2:02 AM
hi, ext.net team?
how to dynamic add a column to the gridpanel through codebehind or javascript?, do you have example or any idea?

Daniil
Jul 22, 2013, 7:12 AM
Hi @tobros,

Please see Add Column and Insert Column.
http://examples2.ext.net/#/GridPanel/ColumnModel/Reconfigure/

To add a Column in JavaScript you can use:

App.GridPanel1.addColumn({ text: "New Column", dataIndex: "someDataIndex" });

tobros
Jul 25, 2013, 3:03 AM
Hi @tobros,

Please see Add Column and Insert Column.
http://examples2.ext.net/#/GridPanel/ColumnModel/Reconfigure/

To add a Column in JavaScript you can use:

App.GridPanel1.addColumn({ text: "New Column", dataIndex: "someDataIndex" });

I try to add column in codebihind , but no No effect


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using TobrosCWTAccess;
using TobrosCWTAccess.Common;
using TobrosCWTEf;
using TobrosDto;
using TobrosException;

namespace TobrosCWT.pages.pingzheng
{
public partial class pingzhengluru1 : System.Web.UI.Page
{
Gy_AccInformationRepository _gyAccInformationRepository = new Gy_AccInformationRepository();
readonly VouchMainService _vouchMainService = new VouchMainService();
VouchClassService vouchClassService = new VouchClassService();
List<Cwzz_AccVouchSub> accVouchSubs = new List<Cwzz_AccVouchSub>();
AccVouchSubService accVouchSubService = new AccVouchSubService();
SubjectRepository subjectRepository = new SubjectRepository();
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{

CreateBlankRow();
df_date.SelectedDate = DateTime.Now;
InitVouchNote();
InitVouchClass();
}
}

private void CreateBlankRow()
{

var ll = new List<Cwzz_AccVouchSub>();
for (int i = 0; i < 5; i++)
{
var accVouchSub = new Cwzz_AccVouchSub();
ll.Add(accVouchSub);
}
this.store_pz.DataSource = ll;
this.store_pz.DataBind();

}


private void InitVouchClass()
{
List<Cwzz_VouchClass> ll = vouchClassService.VouchClasses();
store_VCC.DataSource = ll;
store_VCC.DataBind();

}


private void InitVouchNote()
{
int y = DateTime.Now.Year;
int m = DateTime.Now.Month;
int vp = _gyAccInformationRepository.GeTVoucherPeriod();
int max = vp == 1 ? (_vouchMainService.MaxVouchId(y, m) + 1) : (_vouchMainService.MaxVouchId(y) + 1);
nf_VouchNo.Value = max.ToString();
}
[DirectMethod]
public void Edit(int id, string field, string oldValue, string newValue, object customer)
{
string message = "<b>Property:</b> {0}<br /><b>Field:</b> {1}<br /><b>Old Value:</b> {2}<br /><b>New Value:</b> {3}";

// Send Message...
X.Msg.Notify("Edit Record #" + id.ToString(), string.Format(message, id, field, oldValue, newValue)).Show();

this.gp_pingzheng.GetStore().GetById(id).Commit();
}
protected void NodeDbClick(object sender, DirectEventArgs e)
{
string id = e.ExtraParams["id"];
string text = e.ExtraParams["text"];
string leaf = e.ExtraParams["leaf"];
if (leaf == "true")
{
ddf_kemu.SetValue(id, text);
}
bool isforeign = subjectRepository.IsForeignFlag(id);
if (isforeign)
{
ModelField field = new ModelField("mf_foreign");
store_pz.AddField(field,2);
this.store_pz.Model[0].Fields.Insert(2, field);
Column col = new Column();
col.Text = "Change %";
col.Width = 75;
col.Sortable = true;
col.DataIndex = "pctChange";
col.Renderer.Fn = "pctChange";

ComboBox cb = new ComboBox();
cb.Items.Add(new Ext.Net.ListItem("1", "1"));
cb.Items.Add(new Ext.Net.ListItem("2", "2"));
cb.Items.Add(new Ext.Net.ListItem("3", "3"));
this.Controls.Add(cb);

col.Editor.Add(cb);

this.gp_pingzheng.AddColumn(col);
this.gp_pingzheng.Reload();

}
}


private void SaveAccVouchSub(int pk)
{
// string grid1Json = e.ExtraParams["Grid1"];
// Dictionary<string, string>[] grid1Data = JSON.Deserialize<Dictionary<string, string>[]>(grid1Json);
foreach (var cwzzAccVouchSub in accVouchSubs)
{
cwzzAccVouchSub.VouchId = pk;
}
accVouchSubService.BatchSave(accVouchSubs);
}

private void SaveVouchMain(int pk)
{
int year = df_date.SelectedDate.Year;
int period = df_date.SelectedDate.Month;
DateTime Ddate = df_date.SelectedDate;
string vouchClassCode = cb_VouchClassCode.SelectedItem.Value;
int vouchNo = Convert.ToInt32(nf_VouchNo.Value);
_vouchMainService.AddVouchMain(pk, year, period, Ddate, vouchClassCode, vouchNo);
InitVouchNote();
}

private bool CheckData(DirectEventArgs e)
{
string grid1Json = e.ExtraParams["Grid1"];
Dictionary<string, string>[] grid1Data = JSON.Deserialize<Dictionary<string, string>[]>(grid1Json);
string sum = e.ExtraParams["sum"];
int index = 0;
foreach (Dictionary<string, string> row in grid1Data)
{
if (IsAllNull(row)) continue;
else
{
index++;
if (row["Jfje"] != "0" && row["Dfje"] != "0")
{
ExceptionTool.alert("借方金额与贷方金额不能同时录入");
return false;
}
else if (row["Digest"] == null)
{
ExceptionTool.alert("请填写摘要");
return false;
}
else if (row["Ccode"] == null)
{
ExceptionTool.alert("请选择会计科目");
return false;
}
else if (row["Jfje"] == null && row["Dfje"] == null)
{
ExceptionTool.alert("请填写借方金额或贷方金额");
return false;
}
var cwzzAccVouchSub = new Cwzz_AccVouchSub
{
SerialID = index,
Digest = row["Digest"],
Ccode = row["Ccode"],
Jfje = decimal.Parse(row["Jfje"]),
Dfje = decimal.Parse(row["Dfje"])
};
accVouchSubs.Add(cwzzAccVouchSub);

}
}
if (JeEqual(sum))
{
return false;
}
return true;
}

/// <summary>
/// 判断借贷是否平衡
/// </summary>
/// <param name="sum"></param>
/// <returns>返回true表示借贷不平或者借贷为0</returns>
private static bool JeEqual(string sum)
{
var pzSumDto = JSON.Deserialize<PzSumDto>(sum);
int jfje = pzSumDto.Jfje;
int dfje = pzSumDto.Dfje;
if (jfje != dfje)
{
// X.Msg.Alert("ssss", pzSumDto.Jfsl).Show();
ExceptionTool.alert("录入借贷不平");
return true;
}
else if (jfje == 0 && dfje == 0)
{
ExceptionTool.alert("请录入金额");
return true;
}
return false;
}

private bool IsAllNull(Dictionary<string, string> row)
{
return row["Digest"] == null && row["Ccode"] == null && row["Jfje"] == "0" && row["Dfje"] == "0"
? true
: false;
}
[DirectMethod]
private void AddRow()
{

}
[DirectMethod]
public void DeleteRow()
{
X.Msg.Alert("info", "delete a row").Show();
}

protected void e_save(object sender, DirectEventArgs e)
{
if (CheckData(e))
{
//保存主表
int pk = _vouchMainService.CreatePk();
SaveVouchMain(pk);
SaveAccVouchSub(pk);
//保存上传附件
UploadFiles(pk);
ExceptionTool.alert("凭证录入成功");
}

}
protected void e_doclick(object sender, DirectEventArgs e)
{

var currentCount = int.Parse(e.ExtraParams["currentCount"]);
var neededCount = (int)this.nf_doc.Number;
if (neededCount > 0)
{
int panelsToAdd = neededCount - currentCount;

if (panelsToAdd > 0)
{
for (int i = 1; i <= panelsToAdd; i++)
{
this.GetPanel(i + currentCount).AddTo(this.w_docwin);
}
}
else if (panelsToAdd < 0)
{
X.Js.Call("removeFrom", this.w_docwin.ConfigID, -panelsToAdd, currentCount);
}
this.w_docwin.Show();
}


}
private Ext.Net.Panel GetPanel(int index)
{
return new Ext.Net.Panel()
{
Title = "附件" + index,
Items =
{
new TextField() { ID="tfname"+index,FieldLabel = "附件名称" },
new TextField() { ID="tfdesc"+index,FieldLabel = "附件描述" },
new TextField() { ID="tfother"+index,FieldLabel = "其他描述" },
new FileUploadField(){ID = "fuf"+index,FieldLabel="附件",Icon=Ext.Net.Icon.ImageAdd,ButtonText=""}
}
};
}
protected void e_savenew(object sender, DirectEventArgs e)
{


if (CheckData(e))
{
//保存主表
int pk = _vouchMainService.CreatePk();
SaveVouchMain(pk);
SaveAccVouchSub(pk);
//保存上传附件
UploadFiles(pk);

ExceptionTool.alert("凭证录入成功");
CreateBlankRow();
}
}

private void UploadFiles(int vouchId)
{
var neededCount = (int)this.nf_doc.Number;
for (int i = 0; i < neededCount; i++)
{
var tfname = X.GetCmp<TextField>("tfname" + (i + 1));
string tfnameTxt = tfname.Text;
var tfdesc = X.GetCmp<TextField>("tfdesc" + (i + 1));
string tfdescTxt = tfdesc.Text;
var tfother = X.GetCmp<TextField>("tfother" + (i + 1));
string tfotherTxt = tfother.Text;
var fuf = X.GetCmp<FileUploadField>("fuf" + (i + 1));
HttpPostedFile postedFile = fuf.PostedFile;

Random ran = new Random();
string sNewName = DateTime.Now.ToString(@"yyyy-MM-dd-HH-mm-ss") + ran.Next(100, 999)
+ Path.GetExtension(fuf.PostedFile.FileName);
string strPath = Server.MapPath("~/Uploads/" + System.DateTime.Now.Year.ToString() + "/" + sNewName);
//创建目录
if (!Directory.Exists(Path.GetDirectoryName(strPath)) )
{
Directory.CreateDirectory(Path.GetDirectoryName(st rPath));
}

try
{
var docLists = new Cwzz_DocLists
{
name = tfnameTxt,
discribe = tfdescTxt,
other = tfotherTxt,
path = strPath,
VouchId = vouchId
};
DataAccess.Insert<Cwzz_DocLists>(docLists);
DataAccess.Commit();
fuf.PostedFile.SaveAs(strPath);
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.INFO,
Title = "提示",
Message = "上传成功"
});
}
catch (Exception ex)
{
ExceptionTool.alert("上传失败");
}
}
}
}

}



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pingzhengluru1.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.pingzhengluru1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>凭证录入</title>
<link href="../../images/style.css" rel="stylesheet" />
<style type="text/css">
.my-label {
border-left: solid 1px #C5C5C5;
text-align: right;
}
.my-cell {
letter-spacing: 13px;
}
</style>
<script type="text/javascript">
Ext.onReady(function () {
Ext.Date.dayNames = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']; // specify the correct text here

Ext.picker.Date.override({
dayNames: Ext.Date.dayNames
});
});
var edit = function (editor, e) {
/*
"e" is an edit event with the following properties:

grid - The grid
record - The record that was edited
field - The field name that was edited
value - The value being set
originalValue - The original value for the field, before the edit.
row - The grid table row
column - The grid Column defining the column that was edited.
rowIdx - The row index that was edited
colIdx - The column index that was edited
*/

// Call DirectMethod
if (e.value !== e.originalValue) {
// App.direct.Edit(e.record.data.ID, e.field, e.originalValue, e.value, e.record.data);
}
};

var rd_km = function (value) {
if (value != null && value != '') {
var r = App.ts_kemu.getNodeById(value);
if (Ext.isEmpty(r)) {
return "";
}
return r.data.text;
}
};

var docmd = function (item, command, record, recordIndex, cellIndex) {
if (command == "delete") {
// #{store_pz}.removeAt(recordIndex);
App.store_pz.removeAt(recordIndex);
}
if (command == "add") {
// #{store_pz}.insert(recordIndex-1,record);
App.store_pz.insert(recordIndex, {});
}
}
var removeFrom = function (win, countToRemove, totalCount) {
win = App[win];

var items = win.items;

Ext.suspendLayouts();
for (var i = 1; i <= countToRemove; i++) {
win.remove(items.getAt(totalCount - i));
}

Ext.resumeLayouts(true);

if (win.items.length > 0)
win.items.first().getBody().el.setVisible(true);
};

var fn_itemclick = function (item, td, cellIndex, record, tr, rowIndex, e) {
var cls = Ext.fly(td).getAttribute("class");
var clsWithColumnId = cls.substr(cls.indexOf("x-grid-cell-") + 12);
var columnId = clsWithColumnId.substr(0, clsWithColumnId.indexOf(" "));
var column = Ext.getCmp(columnId);

if (App.col_jfje.contains(column)) {

} else {

}
}

</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" Locale="zh-CN"></ext:ResourceManager>
<ext:DatePicker ID="DatePicker1" runat="server" />

<ext:Viewport ID="Viewport1" runat="server" Padding="10">
<Items>
<ext:Window runat="server" Width="320" ID="w_docwin" Hidden="True" Modal="True" Title="附件管理" Layout="AccordionLayout">
</ext:Window>
<ext:Button ID="Button1" runat="server" Text="刷新" Icon="ArrowRefresh" Cls="mr5">
<Listeners>
<Click Handler="window.location='pingzhengluru.aspx'">
</Click>
</Listeners>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="保存并新增" Cls="mr5" Icon="ApplicationAdd"></ext:Button>
<ext:Button ID="Button3" runat="server" Text="保存" Icon="TableSave"></ext:Button>
<ext:Panel ID="Panel1" Cls="pingzheng" runat="server">
<Items>
<ext:Panel ID="Panel2" runat="server" Layout="ColumnLayout" PaddingSpec="20px 20px;" Border="false">

<Items>
<ext:Panel ID="Panel3" runat="server" ColumnWidth=".4" Height="36" Layout="HBoxLayout" Border="false">
<Items>
<ext:Label ID="Label1" runat="server" Text="凭证字" Cls="mr5"></ext:Label>
<ext:ComboBox ID="cb_VouchClassCode" Editable="False" InputWidth="120" runat="server" DisplayField="VouchClassName" ValueField="VouchClassCode" Cls="mr5">
<Store>
<ext:Store runat="server" ID="store_VCC">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="VouchClassCode">
<Fields>
<ext:ModelField runat="server" Name="VouchClassCode"></ext:ModelField>
<ext:ModelField runat="server" Name="VouchClassName"></ext:ModelField>
</Fields>
</ext:Model>
</Model>

</ext:Store>
</Store>
<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>
</ext:ComboBox>

<ext:NumberField ID="nf_VouchNo" InputWidth="60" LabelAlign="Right" runat="server" Cls="mr5">
</ext:NumberField>
<ext:Label ID="l_VouchNo" runat="server" Text="号" Cls="mr5"></ext:Label>
<ext:Label ID="Label3" runat="server" Text="日期" Cls="mr5"></ext:Label>
<ext:DateField ID="df_date" Format="yyyy-MM-dd" runat="server" InputWidth="90"></ext:DateField>
</Items>
</ext:Panel>
<ext:Panel ID="Panel4" runat="server" ColumnWidth=".2" StyleSpec="text-align:center;" Border="false">
<Items>
<ext:Label ID="Label4" runat="server" Text="记账凭证" StyleSpec="font-size:30px;"></ext:Label>
</Items>
</ext:Panel>

<ext:Panel CellCls="last-field" ID="Panel5" Height="36" runat="server" ColumnWidth=".4" StyleSpec="text-align:right;" Layout="HBoxLayout" Border="false">
<LayoutConfig>
<ext:HBoxLayoutConfig Pack="End" />
</LayoutConfig>
<Items>
<ext:Label ID="Label5" runat="server" Text="附单据" Cls="mr5"></ext:Label>
<ext:NumberField Icon="TextListNumbers" ID="nf_doc" runat="server" InputWidth="60" EmptyText="0">
<DirectEvents>
<IconClick OnEvent="e_doclick">
<ExtraParams>
<ext:Parameter Name="currentCount" Value="App.w_docwin.items.getCount()" Mode="Raw" />
</ExtraParams>
</IconClick>
</DirectEvents>

</ext:NumberField>

</Items>
</ext:Panel>

</Items>
</ext:Panel>
<ext:GridPanel runat="server" ID="gp_pingzheng" AutoScroll="True" MinWidth="900" MinHeight="240">

<Store>
<ext:Store runat="server" ID="store_pz">
<Model>
<ext:Model ID="Model2" runat="server">
<Fields>
<ext:ModelField runat="server" Name="Digest"></ext:ModelField>
<ext:ModelField runat="server" Name="Ccode"></ext:ModelField>
<ext:ModelField runat="server" Name="Jfje" Type="Int"></ext:ModelField>
<ext:ModelField runat="server" Name="Dfje" Type="Int"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:SummaryColumn ID="Column1" runat="server" Text="摘要" DataIndex="Digest" Align="Right">
<SummaryRenderer Handler="return '合计:'"></SummaryRenderer>
<Editor>
<ext:TextField ID="TextField1" runat="server"></ext:TextField>
</Editor>
</ext:SummaryColumn>
<ext:Column ID="col_kjkm" runat="server" Text="会计科目" DataIndex="Ccode" Align="Right" Width="200">
<Renderer Fn="rd_km"></Renderer>
<Editor>
<ext:DropDownField ID="ddf_kemu" runat="server" Mode="ValueText">
<Component>
<ext:TreePanel runat="server" ID="tp_subject" MaxHeight="400" Shadow="false" UseArrows="true" AutoScroll="true" Animate="true" RootVisible="false">
<View>
<ext:TreeView ID="TreeView1" runat="server" LoadMask="true" />
</View>
<Store>
<ext:TreeStore runat="server" ID="ts_kemu">

<Proxy>
<ext:AjaxProxy Url="~/BasicInfoAshx/SubjectTree.ashx">
</ext:AjaxProxy>
</Proxy>
</ext:TreeStore>
</Store>
<DirectEvents>
<ItemDblClick OnEvent="NodeDbClick">
<ExtraParams>
<ext:Parameter runat="server" Name="id" Value="record.data.id" Mode="Raw" />
<ext:Parameter runat="server" Name="text" Value="record.data.text" Mode="Raw" />
<ext:Parameter runat="server" Name="leaf" Value="record.data.leaf" Mode="Raw" />
</ExtraParams>
</ItemDblClick>
</DirectEvents>
</ext:TreePanel>
</Component>
</ext:DropDownField>
</Editor>
</ext:Column>


<ext:SummaryColumn runat="server" Text="借方金额" Align="Right" Width="215" Flex="1" SummaryType="Sum" ID="sc_jf" DataIndex="Jfje" TdCls="my-cell">
<HeaderItems>
<ext:Container ID="Container1" runat="server" StyleSpec="padding-right:11px;">
<LayoutConfig>
<ext:HBoxLayoutConfig Pack="End" />
</LayoutConfig>
<Defaults>
<ext:Parameter Name="cls" Value="my-label" Mode="Value" />
</Defaults>
<Items>
<ext:Label ID="Label2" StyleSpec="text-align:center;" runat="server" Text="亿" Width="20" />
<ext:Label ID="Label6" runat="server" Text="千" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label7" runat="server" Text="百" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label8" runat="server" Text="十" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label9" runat="server" Text="万" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label10" runat="server" Text="千" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label11" runat="server" Text="百" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label12" runat="server" Text="十" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label13" runat="server" Text="元" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label14" runat="server" Text="角" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label15" runat="server" Text="分" Width="20" StyleSpec="text-align:center;" />
</Items>
</ext:Container>
</HeaderItems>

<Renderer Handler="if(value!=null&&value!='')return value +'';" />
<SummaryRenderer Handler=" if(value!=0&&value!=null)return value +'';" />
<Editor>
<ext:NumberField ID="NumberField1" runat="server"></ext:NumberField>
</Editor>

</ext:SummaryColumn>

<ext:SummaryColumn SummaryType="Sum" ID="sc_df" runat="server" Text="贷方金额" DataIndex="Dfje" Flex="1" Align="Right" TdCls="my-cell">
<HeaderItems>
<ext:Container ID="Container2" runat="server" StyleSpec="padding-right:11px;">
<LayoutConfig>
<ext:HBoxLayoutConfig Pack="End" />
</LayoutConfig>
<Defaults>
<ext:Parameter Name="cls" Value="my-label" Mode="Value" />
</Defaults>
<Items>
<ext:Label ID="Label16" StyleSpec="text-align:center;" runat="server" Text="亿" Width="20" />
<ext:Label ID="Label17" runat="server" Text="千" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label18" runat="server" Text="百" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label19" runat="server" Text="十" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label20" runat="server" Text="万" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label21" runat="server" Text="千" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label22" runat="server" Text="百" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label23" runat="server" Text="十" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label24" runat="server" Text="元" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label25" runat="server" Text="角" Width="20" StyleSpec="text-align:center;" />
<ext:Label ID="Label26" runat="server" Text="分" Width="20" StyleSpec="text-align:center;" />
</Items>
</ext:Container>
</HeaderItems>
<Renderer Handler="if(value!=null&&value!='')return value +'';" />
<SummaryRenderer Handler="if(value!=0)return value +'';" />
<Editor>
<ext:NumberField ID="NumberField4" runat="server"></ext:NumberField>
</Editor>
</ext:SummaryColumn>

<ext:CommandColumn ID="CommandColumn1" runat="server" Text="操作" Align="Right">
<Commands>
<ext:GridCommand Icon="Delete" CommandName="delete">
<ToolTip Text="删除"></ToolTip>
</ext:GridCommand>
<ext:CommandSeparator />
<ext:GridCommand Icon="Add" CommandName="add">
<ToolTip Text="新增"></ToolTip>
</ext:GridCommand>
</Commands>
<Listeners>
<Command Fn="docmd" />
</Listeners>
</ext:CommandColumn>
</Columns>
</ColumnModel>
<Features>
<ext:Summary ID="Summary1" runat="server" />
</Features>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server">
<Listeners>
<Edit Fn="edit" />
</Listeners>
</ext:CellEditing>
</Plugins>
<Buttons>
<ext:Button runat="server" ID="btn_savenew" Text="保存并新增">
<DirectEvents>
<Click OnEvent="e_savenew" IsUpload="true" Before="
Ext.Msg.wait('正在操作中...', '处理中...');"
Failure="Ext.Msg.show({
title : 'Error',
msg : 'Error during uploading',
minWidth: 200,
modal : true,
icon : Ext.Msg.ERROR,
buttons : Ext.Msg.OK
});">
<ExtraParams>
<ext:Parameter Name="sum" Value="App.Summary1.summaryRecord.data" Mode="Raw" />
<ext:Parameter Name="Grid1" Value="Ext.encode(#{gp_pingzheng}.getRowsValues({selected Only : false}))" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" ID="btn_save" Text="保存">
<DirectEvents>
<Click OnEvent="e_save">
<ExtraParams>
<ext:Parameter Name="sum" Value="App.Summary1.summaryRecord.data" Mode="Raw" />
<ext:Parameter Name="Grid1" Value="Ext.encode(#{gp_pingzheng}.getRowsValues({selected Only : false}))" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>

</ext:GridPanel>
</Items>
</ext:Panel>


</Items>
</ext:Viewport>
</form>
</body>
</html>

Daniil
Jul 25, 2013, 5:14 AM
Unfortunately, I cannot run the test case.

Please post a NodeDbClick's response.

tobros
Jul 26, 2013, 3:24 AM
Unfortunately, I cannot run the test case.

Please post a NodeDbClick's response.

I try to code an test case ,but some error
1,data not show in gridpanel.
2,button event not be triggered
my code below


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm7" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.gridstore.DataSource = new Student().GetStudent();
this.gridstore.DataBind();
this.gp.Reload();
}
public class Student
{
int id;
string name;

public List<Student> GetStudent()
{
return new List<Student> {
new Student { id = 1, name = "name1" },
new Student { id = 2, name = "name2" }
};
}
}

protected void addevent(object sender, DirectEventArgs e)
{
X.Msg.Alert("ssss","ssssss").Show();
}

</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gp">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="新增一列" ID="btnadd">
<DirectEvents>
<Click OnEvent="addevent"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="gridstore">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="name"></ext:ModelField>
</Fields>
</ext:Model>
</Model>

</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
<ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>

Baidaly
Jul 26, 2013, 3:50 AM
Hello!

Your properties should be public:



<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.gridstore.DataSource = new Student().GetStudent();
this.gridstore.DataBind();
}
//this.gp.Reload();
}
public class Student
{
public int id { get; set; }
public string name { get; set; }

public List<Student> GetStudent()
{
return new List<Student> {
new Student { id = 1, name = "name1" },
new Student { id = 2, name = "name2" }
};
}
}

protected void addevent(object sender, DirectEventArgs e)
{
X.Msg.Alert("ssss", "ssssss").Show();
}

</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gp">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="新增一列" ID="btnadd">
<DirectEvents>
<Click OnEvent="addevent"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="gridstore">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="name"></ext:ModelField>
</Fields>
</ext:Model>
</Model>

</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
<ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>




button event not be triggered

I couldn't reproduce. In the example above it works perfectly.

tobros
Jul 26, 2013, 8:28 AM
when click "新增一列",only show column header, data not be rendered


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm7" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.gridstore.DataSource = new Student().GetStudent();
this.gridstore.DataBind();
}
}
public class Student
{
public int id { get; set; }
public string name { get; set; }
public string newname { get; set; }

public List<Student> GetStudent()
{
return new List<Student> {
new Student { id = 1, name = "name1",newname="newname1"},
new Student { id = 2, name = "name2",newname="newname2" }
};
}
}

protected void addevent(object sender, DirectEventArgs e)
{
Column col = new Column();
col.Text = "new text";
col.Width = 75;
col.Sortable = true;
col.DataIndex = "newname";


ComboBox cb = new ComboBox();
cb.Items.Add(new Ext.Net.ListItem("1", "1"));
cb.Items.Add(new Ext.Net.ListItem("2", "2"));
cb.Items.Add(new Ext.Net.ListItem("3", "3"));
this.Controls.Add(cb);

col.Editor.Add(cb);

this.gp.AddColumn(col);

ModelField mf = new ModelField();
mf.Name = "newname";
this.gridstore.Fields.Add(mf);
}

</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gp">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="新增一列" ID="btnadd">
<DirectEvents>
<Click OnEvent="addevent"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="gridstore">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="name"></ext:ModelField>
</Fields>
</ext:Model>
</Model>

</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
<ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>

Daniil
Jul 26, 2013, 9:46 AM
When you bind the data in Page_Load, there is no "newname" ModelField in the Store's Model. So, the "newname" stuff is not rendered to client.

You can predefine a ModelField in the Store's Model.

Another solution is to add a ModelField on the fly as you, seems, are trying to add.

this.gridstore.Fields.Add(mf);

But it doesn't add a ModelField during a DirectEvent. You can use

this.gridstore.AddField(mf);
instead.

In this case you will need to load the data again.

this.gridstore.LoadData(new Student().GetStudent());

tobros
Jul 30, 2013, 3:28 AM
When you bind the data in Page_Load, there is no "newname" ModelField in the Store's Model. So, the "newname" stuff is not rendered to client.

You can predefine a ModelField in the Store's Model.

Another solution is to add a ModelField on the fly as you, seems, are trying to add.

this.gridstore.Fields.Add(mf);

But it doesn't add a ModelField during a DirectEvent. You can use

this.gridstore.AddField(mf);
instead.

In this case you will need to load the data again.

this.gridstore.LoadData(new Student().GetStudent());



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm7" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.gridstore.DataSource = new Student().GetStudent();
this.gridstore.DataBind();
}
}
public class Student
{
public int id { get; set; }
public string name { get; set; }
public string newname { get; set; }

public List<Student> GetStudent()
{
return new List<Student> {
new Student { id = 1, name = "name1",newname="newname1"},
new Student { id = 2, name = "name2",newname="newname2" }
};
}
}

protected void addevent(object sender, DirectEventArgs e)
{
Column col = new Column();
col.Text = "new text";
col.Width = 75;
col.Sortable = true;
col.DataIndex = "newname";


ComboBox cb = new ComboBox();
cb.Items.Add(new Ext.Net.ListItem("1", "1"));
cb.Items.Add(new Ext.Net.ListItem("2", "2"));
cb.Items.Add(new Ext.Net.ListItem("3", "3"));
this.Controls.Add(cb);

col.Editor.Add(cb);

this.gp.AddColumn(col);

ModelField mf = new ModelField();
mf.Name = "newname";
this.gridstore.AddField(mf);
this.gridstore.LoadData(new Student().GetStudent());
}

</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gp">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="新增一列" ID="btnadd">
<DirectEvents>
<Click OnEvent="addevent"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="gridstore">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="name"></ext:ModelField>
</Fields>
</ext:Model>
</Model>

</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
<ext:Column runat="server" DataIndex="name" Text="名称"></ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>


is it possible to add a label and a dropdownlistbox to the newname1 and newname2?

Daniil
Jul 30, 2013, 4:52 AM
I guess you should define this for the GridPanel:

<Plugins>
<ext:CellEditing runat="server" />
</Plugins>

Also please remove this:

this.Controls.Add(cb);

tobros
Jul 30, 2013, 7:30 AM
I guess you should define this for the GridPanel:

<Plugins>
<ext:CellEditing runat="server" />
</Plugins>

Also please remove this:

this.Controls.Add(cb);

can do this for example?
6654
a dropdown list and two textfields in the cell?

Daniil
Jul 30, 2013, 10:29 AM
Sorry, I am not quite getting it.

Do you need a ComboBox and two TextFields in a single cell?

tobros
Jul 31, 2013, 1:00 AM
Sorry, I am not quite getting it.

Do you need a ComboBox and two TextFields in a single cell?

yes. it is

Baidaly
Jul 31, 2013, 2:04 AM
Hello!

In this case you should use ComponentColumn like in the example below. You can see all examples here: http://examples2.ext.net/#/search/componentcolumn :



<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public double Change { get; set; }
public double PctChange { get; set; }
public DateTime LastChange { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindData();
}
}

private void BindData()
{
Store store = this.GridPanel1.GetStore();
store.DataSource = this.GetData();
store.DataBind();
}

private List<Company> GetData()
{
return new List<Company>
{
new Company { ID = 1, Name = "3m Co", Price = 71.72, Change = 0.02, PctChange = 0.03, LastChange = DateTime.Now },
new Company { ID = 2, Name = "Alcoa Inc", Price = 29.01, Change = 0.42, PctChange = 1.47, LastChange = DateTime.Now },
new Company { ID = 3, Name = "Altria Group Inc", Price = 83.81, Change = 0.28, PctChange = 0.34, LastChange = DateTime.Now },
new Company { ID = 4, Name = "American Express Company", Price = 52.55, Change = 0.01, PctChange = 0.02, LastChange = DateTime.Now },
new Company { ID = 5, Name = "American International Group, Inc.", Price = 64.13, Change = 0.31, PctChange = 0.49, LastChange = DateTime.Now },
new Company { ID = 6, Name = "AT&T Inc.", Price = 31.61, Change = -0.48, PctChange = -1.54, LastChange = DateTime.Now },
new Company { ID = 7, Name = "Boeing Co.", Price = 75.43, Change = 0.53, PctChange = 0.71, LastChange = DateTime.Now },
new Company { ID = 8, Name = "Caterpillar Inc.", Price = 67.27, Change = 0.92, PctChange = 1.39, LastChange = DateTime.Now },
new Company { ID = 9, Name = "Citigroup, Inc.", Price = 49.37, Change = 0.02, PctChange = 0.04, LastChange = DateTime.Now }
};
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<h1>Editable GridPanel With Save To [DirectMethod]</h1>

<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Editable GridPanel"
Width="600"
Height="350">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Price" Type="Float" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="ID" DataIndex="ID" Width="35" />
<ext:Column runat="server" Text="Name" DataIndex="Name" Flex="1">
<Editor>
<ext:TextField runat="server" />
</Editor>
</ext:Column>
<ext:Column runat="server" Text="Price" DataIndex="Price">
<Renderer Format="UsMoney" />
<Editor>
<ext:NumberField runat="server" />
</Editor>
</ext:Column>
<ext:ComponentColumn runat="server" Text="Price" DataIndex="Price" Editor="True" Width="140">
<Component>
<ext:Container runat="server" Layout="HBoxLayout">
<Items>
<ext:NumberField runat="server" ItemID="AmountValue" Width="80"></ext:NumberField>
<ext:ComboBox runat="server" ItemID="Currency" Flex="1">
<Items>
<ext:ListItem Text="USD" Value="1" Mode="Raw" />
<ext:ListItem Text="EURO" Value="2" Mode="Raw" />
</Items>
</ext:ComboBox>
</Items>
</ext:Container>
</Component>
<Listeners>
<Bind Handler="
cmp.suspendLayout = true;
cmp.down('#AmountValue').setValue(record.get('Pric e'));
cmp.down('#Currency').setValue(1);
cmp.suspendLayout = false;
cmp.doLayout();
"></Bind>
</Listeners>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CellSelectionModel runat="server" />
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>