Feb 28, 2015, 10:34 PM
Add new Row to GridPanel Clear all componentcolmn data and store date
Hi All,
I have the below code, when I am trying to insert a new row using Add button, it works well for first row but any new insert it clear all gird !!.
Please help me, I cannot find any solution for this issue !
I have the below code, when I am trying to insert a new row using Add button, it works well for first row but any new insert it clear all gird !!.
Please help me, I cannot find any solution for this issue !
@model IEnumerable<WebApplication1.Models.lib_MainData>
@* @Html.RenderPartial(partial_name,model,data_view) *@
@{
var pname = "";
switch ((int)ViewData["SourceTypeID"]) {
case 1:
pname = "_MainDataBooks";
break;
case 2:
pname = "_MainDataTheses";
break;
case 3:
pname = "_MainDataConference_Publication";
break;
case 4:
pname = "_MainDataManuscripts";
break;
case 5:
pname = "_MainDataPeriodicals_and_Serials";
break;
case 6:
pname = "_MainDataMaps";
break;
case 7:
pname = "_MainDataImages";
break;
case 8:
pname = "_MainDataMusic_Scores";
break;
case 9:
pname = "_MainDataPatent_Document";
break;
case 10:
pname = "_MainDataSound_Recording";
break;
case 11:
pname = "_MainDataVideo_Recording";
break;
case 12:
pname = "_MainDataMicroforms";
break;
case 13:
pname = "_MainDataSlides_Transparencies";
break;
case 14:
pname = "_MainDataObjects_and_Realia";
break;
case 15:
pname = "_MainDataKits";
break;
case 16:
pname = "_MainDataComputer_Files";
break;
case 17:
pname = "_MainDataAnother";
break;
default:
pname = "_MainDataBooks";
break;
}
}
@(Html.X().Window()
.ID("MainData")
.Title("Set Main Data")
.Width(550)
.Layout(LayoutType.Form)
.Icon(Icon.ApplicationAdd)
.Modal(true)
.Items(
Html.X().FormPanel()
.ID("form1")
.JsonSubmit(true)
.Url("/Cataloging/SaveMainData")//save route to the same controller and SaveMain action !!
.Items(
Html.X().TextField()
.Disabled(true)
.EmptyText("Library Name")
.FieldLabel("Library Name")
.Text(ViewData["Library"] + "")
.Name("LibraryName")
,
Html.X().TextField()
.Disabled(true)
.EmptyText("Source Type Name")
.FieldLabel("Source Type")
.Text(ViewData["TypeNameEn"] + "")
.Name("Source Type Name")
,
Html.X().TextField()
.Disabled(true)
.EmptyText("Date")
.FieldLabel("Date")
.Text(ViewData["Date"] + "")
.Name("Date")
,
Html.X().TextField()
.Disabled(true)
.EmptyText("Time")
.FieldLabel("Time")
.Text(ViewData["Time"] + "")
.Name("Time")
,
Html.X().Hidden()
.Text(ViewData["SourceTypeID"] + "")
.Name("SourceTypeID")
,
Html.X().FieldSet()
.Width(515)
.Title("Main Data")
.Defaults(d =>
{
d.Add(new Parameter("LabelWidth", "115"));
})
.ItemsFromPartial(pname, Model, ViewData)//end of set
,//grid inside the form, we need to use its values to add it as well.
Html.X().GridPanel()
.ID("MainDataDetail")
.Title("Main Data Detail")
.Width(515)
.Height(200)
.Store(
Html.X().Store()
.ID("GridStore")
.Model(Html.X().Model()
//.IDProperty("MainDataDetailID")
.Fields(
new ModelField("CatalogingSourceID", ModelFieldType.Int) { Mapping = "CatalogingSourceID" },
new ModelField("CatalogingSource", ModelFieldType.String) { Mapping = "CatalogingSource" }
)
)
.Listeners(l => {
l.Add.Fn = "function(store, records, index, eOpts){console.log(store);console.log(records);console.log(index);console.log(eOpts);}";
})
//.DataSource(ViewData["lib_MainDataDetail"])
//.DataBind()
)
.ColumnModel(
Html.X().ComponentColumn()
.Editor(true)
.DataIndex("CatalogingSourceID")
.Flex(1)
.Text("Cataloging Source")
.Component(Html.X().ComboBox()
.DisplayField("CatalogingSourceNameEN")
.ValueField("CatalogingSourceID")
.Store(Html.X().Store()
.Model(Html.X().Model()
.IDProperty("CatalogingSourceID")
.Fields(
new ModelField("CatalogingSourceID", ModelFieldType.String) { Mapping = "CatalogingSourceID" },
new ModelField("CatalogingSourceNameEN", ModelFieldType.String) { Mapping = "CatalogingSourceNameEN" }
)
)
.DataSource(ViewData["CatalogingSources"])
.DataBind()
)
),
Html.X().ComponentColumn()
.DataIndex("CatalogingSource")
.Editor(true)
.Flex(1)
.Text("Cataloging Source Description")
.Component(Html.X().TextField())//,
/* Html.X().ComponentColumn()
.Width(25)
.PinAllColumns(false)
.AutoWidthComponent(false)
.OverOnly(true)
.Component(
Html.X().Button()
.ToolTip("Pin Editor")
.Icon(Icon.Pencil)
.AllowDepress(true)
.EnableToggle(true)
.Listeners(l => {
l.Toggle.Fn = "function (btn, pressed) {"+
"var columnConfig = btn.column,"+
"column = columnConfig.column;"+
"if (pressed) {"+
"column.pinOverComponent();"+
"column.showComponent(columnConfig.record, true);"+
"} else {"+
"column.unpinOverComponent();"+
"column.hideComponent(true);"+
"}}";
})
)*/
)
.TopBar(
Html.X().Toolbar()
.Items(
Html.X().Button()
.Text("Add")
.Icon(Icon.Add)
.Handler("App.MainDataDetail.store.add({CatalogingSourceID:1,CatalogingSource:''});")
)
)
.Plugins(
Html.X().CellEditing().ClicksToEdit(1)
)
//.SelectionModel(Html.X().CellSelectionModel())
)//end of fieldset items
)
.Buttons(
Html.X().Button()
.ID("SaveMain")
.FormBind(true)
.Text("Save")
.Handler(
"if(App.form1.form.isValid()) {" +
//"var fdata = Ext.util.JSON.encode(App.form1.form.getValues(false));"+
"var gall=App.MainDataDetail.store.getModifiedRecords();" +
"var galldata=[];" +
"for(i=0;i<gall.length;i++){galldata[i]=gall[i].data;}" +//modified
//"var gdata = Ext.util.JSON.encode(galldata);" +
"App.form1.form.submit({" +
" params : { gdata : galldata, fdata : App.form1.form.getValues(false) }," +//it cbecome json on they fly !!!!
" waitMsg:'Saving...'" +
"}); " +
"}else{" +
" Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');" +
"}"
)
//.Handler("App.form1.form.submit({ waitMsg : 'Saving...'});")//save all for and grid, how to applay for grid as well ?
)
)