Apr 18, 2014, 1:11 PM
[CLOSED] Error in rendering component columns in gridpanel.
Hi,
Mine is an ASP.NET MVC razor view application.
Following is my controller ActionMethod
Mine is an ASP.NET MVC razor view application.
Following is my controller ActionMethod
public ActionResult TestMethod()
{
DataTable modelAllValues = new DataTable();
modelAllValues.Columns.Add("Currency_Cd", typeof(int));
modelAllValues.Columns.Add("EffectiveDate1", typeof(double));
modelAllValues.Columns.Add("EffectiveDate1Name", typeof(DateTime));
modelAllValues.Columns.Add("EffectiveDate2", typeof(double));
modelAllValues.Columns.Add("EffectiveDate2Name", typeof(DateTime));
modelAllValues.Columns.Add("EffectiveDate3", typeof(double));
modelAllValues.Columns.Add("EffectiveDate3Name", typeof(DateTime));
modelAllValues.Columns.Add("NewSelectedDate", typeof(DateTime));
modelAllValues.Columns.Add("Pack_CD", typeof(int));
modelAllValues.Columns.Add("PRICE_TYPE", typeof(string));
modelAllValues.Columns.Add("PRICE_TYPE_CD", typeof(int));
modelAllValues.Columns.Add("UpdatedNotes", typeof(string));
DataRow _modelAllValues = modelAllValues.NewRow();
_modelAllValues["Currency_Cd"] = 12;
_modelAllValues["EffectiveDate1"] = 2.42;
_modelAllValues["EffectiveDate1Name"] = "2013/01/01";
_modelAllValues["EffectiveDate2"] = 0.0;
_modelAllValues["EffectiveDate2Name"] = "2013/04/01";
_modelAllValues["EffectiveDate3"] = 0.0;
_modelAllValues["EffectiveDate3Name"] = "2014/04/26";
_modelAllValues["NewSelectedDate"] = "1/1/0001 12:00:00 AM";
_modelAllValues["Pack_CD"] = 824;
_modelAllValues["PRICE_TYPE"] = "Wholesale Purchase Price";
_modelAllValues["PRICE_TYPE_CD"] = 1;
_modelAllValues["UpdatedNotes"] = null;
modelAllValues.Rows.Add(_modelAllValues);
modelAllValues.AcceptChanges();
//2nd row
DataRow _modelAllValues2 = modelAllValues.NewRow();
_modelAllValues2["Currency_Cd"] = 12;
_modelAllValues2["EffectiveDate1"] = 2.60;
_modelAllValues2["EffectiveDate1Name"] = System.DateTime.Now ;
_modelAllValues2["EffectiveDate2"] = 0;
_modelAllValues2["EffectiveDate2Name"] = System.DateTime.Now; ;
_modelAllValues2["EffectiveDate3"] = 323.00;
_modelAllValues2["EffectiveDate3Name"] = System.DateTime.Now; ;
_modelAllValues2["NewSelectedDate"] = "1/1/0001 12:00:00 AM";
_modelAllValues2["Pack_CD"] = 824;
_modelAllValues2["PRICE_TYPE"] = "Pharmacy Purchasing Price";
_modelAllValues2["PRICE_TYPE_CD"] = 2;
_modelAllValues2["UpdatedNotes"] = null;
modelAllValues.Rows.Add(_modelAllValues2);
//2nd table
DataTable CurrencyDTO = new DataTable();
CurrencyDTO.Columns.Add("Active_IND", typeof(bool));
CurrencyDTO.Columns.Add("ConfiguredCurrencies", typeof(int));
CurrencyDTO.Columns.Add("Currency_CD", typeof(int));
CurrencyDTO.Columns.Add("Currency_CD_STR", typeof(string));
CurrencyDTO.Columns.Add("Currency_DISC", typeof(string));
CurrencyDTO.Columns.Add("Currency_Symbol", typeof(string));
CurrencyDTO.Columns.Add("Notes", typeof(string));
DataRow _CurrencyDTO = CurrencyDTO.NewRow();
_CurrencyDTO["Active_IND"] = false;
_CurrencyDTO["ConfiguredCurrencies"] = 0;
_CurrencyDTO["Currency_CD"] = 12;
_CurrencyDTO["Currency_CD_STR"] = null;
_CurrencyDTO["Currency_DISC"] = "AUD";
_CurrencyDTO["Currency_Symbol"] = null;
_CurrencyDTO["Notes"] = null;
CurrencyDTO.Rows.Add(_CurrencyDTO);
CurrencyDTO.AcceptChanges();
//3rd table
DataTable CommonPackValues = new DataTable();
CommonPackValues.Columns.Add("Country", typeof(string));
CommonPackValues.Columns.Add("Discontinued", typeof(string));
CommonPackValues.Columns.Add("LastUpdated", typeof(string));
CommonPackValues.Columns.Add("LocalName", typeof(string));
CommonPackValues.Columns.Add("MarketingAuthority", typeof(string));
CommonPackValues.Columns.Add("MarketingStatus", typeof(string));
CommonPackValues.Columns.Add("NewDate", typeof(DateTime));
CommonPackValues.Columns.Add("ParentCompany", typeof(string));
CommonPackValues.Columns.Add("PriceDescription", typeof(string));
CommonPackValues.Columns.Add("Region", typeof(string));
CommonPackValues.Columns.Add("TheraputicCategory", typeof(string));
CommonPackValues.Columns.Add("UnitOfMeasureBasis", typeof(string));
DataRow _CommonPackValues = CommonPackValues.NewRow();
_CommonPackValues["Country"] = "AUSTRALIA";
_CommonPackValues["Discontinued"] = "";
_CommonPackValues["LastUpdated"] = "";
_CommonPackValues["LocalName"] = "MOVOX";
_CommonPackValues["MarketingAuthority"] = "GLOBAL";
_CommonPackValues["MarketingStatus"] = "YES";
_CommonPackValues["NewDate"] = "1/1/0001 12:00:00 AM";
_CommonPackValues["ParentCompany"] = "XYZ";
_CommonPackValues["PriceDescription"] = "1 PACK 30 TABLETS ";
_CommonPackValues["Region"] = "ALL";
_CommonPackValues["TheraputicCategory"] = "PRIMARY CARE";
_CommonPackValues["UnitOfMeasureBasis"] = "GLOBAL";
CommonPackValues.Rows.Add(_CommonPackValues);
CommonPackValues.AcceptChanges();
List<EditPack> editpackList = new List<EditPack>();
EditPack editpack = new EditPack{
CURRENCY_CD = 12,
EFFECTIVEDATE1 = "2.42",
EFFECTIVEDATE1Name = "2013/01/01",
EFFECTIVEDATE2 ="",
EFFECTIVEDATE2Name = "2013/04/01",
EFFECTIVEDATE3 = "",
EFFECTIVEDATE3Name="2014/04/26",
NewSelectedDate = Convert.ToDateTime( "1/1/0001 12:00:00 AM"),
Pack_CD =824,
PRICE_TYPE="Pharmacy Purchasing Price",
PRICE_TYPE_CD =2 ,
UpdatedNotes= null
};
editpackList.Add(editpack);
PackPriceViewModelDTO listCombinePack = new PackPriceViewModelDTO();
listCombinePack.CommonPackValues = new EditablePackDTO
{
Country = "AUSTRALIA",
CURRENCY_CD = 2,
Discontinued = "",
LastUpdated = "",
LocalName = "MOVOX",
MarketingAuthority = "GLOBAL",
MarketingStatus = "YES",
NewDate = Convert.ToDateTime("1/1/0001 12:00:00 AM"),
ParentCompany = "XYZ",
PriceDescription = "1 PACK 30 TABLETS ",
Region = "ALL",
TheraputicCategory = "PRIMARY CARE",
UnitOfMeasureBasis = "GLOBAL"
};
//CurrencyDTO curr = new DTO.CurrencyDTO {
// ACTIVE_IND = false,
// ConfiguredCurrencies = null,
// CURRENCY_CD = 12,
// CURRENCY_CD_STR = null,
// CURRENCY_DESC = "AUD",
// CURRENCY_SYMBOL = null,
// NOTES = null
//};
PackPriceViewModelDTO ListCombinePack = new PackPriceViewModelDTO();
//List<EditPack> modelAllValues = _EditPackPriceReadService.GetEditSelectedPackPrices(Convert.ToInt32(824)).TheEntity;
List<object> obj = new List<object>();
foreach (DataRow dr in modelAllValues.Rows)
{
obj.Add(dr);
}
//List<CurrencyDTO> PackCurrency = _EditPackPriceReadService.GetCurrencyByPackId(Convert.ToInt32(824)).TheEntity;
//DataTable dtCurrency = PackCurrency.ConvertToDataTable();
if (obj.Count > 0)
{
ListCombinePack.EditableValues = editpackList;
//ListCombinePack.CommonPackValues = _EditPackPriceReadService.GetEditablePackDetails(5285, 4, 33, 161).TheEntity;
#region GenerateColumns
List<ColumnName> columnNames = new List<ColumnName>();
List<object> Columns = new List<object>();
ColumnName clnm = null;
DataTable dt = modelAllValues;
dt.Columns.Add("NewPrices", typeof(double)); //new column added
foreach (DataRow dr in dt.Rows)
{
//need to set value to NewPrices column
dr["NewPrices"] = string.IsNullOrEmpty(Convert.ToString(dr["EffectiveDate3"])) == false ? Convert.ToDouble(dr["EffectiveDate3"]) : 0.0;
// or set it to some other value
}
dt.Columns.Add("ViewButtons", typeof(string));
foreach (DataRow dr in dt.Rows)
{
//need to set value to NewPrices column
dr["ViewButtons"] = string.IsNullOrEmpty(Convert.ToString(dr["Pack_CD"])) == false ? dr["Pack_CD"] : ""; // or set it to some other value
}
#region HiddenDateField
Column clD = new Column();
ColumnName clnmD = new ColumnName();
clD.Hidden = true;
clnmD.Text = clD.Text = "New Date";
clD.DataIndex = clnmD.DataIndex = "NewSelectedDate";
Columns.Add(clD);
columnNames.Add(clnmD);
#endregion HiddenDateField
#region HiddenPackCD_Field
Column clPckCD = new Column();
ColumnName clnmPckCD = new ColumnName();
clPckCD.Hidden = true;
clnmPckCD.Text = clPckCD.Text = "Pack CD";
clPckCD.DataIndex = clnmPckCD.DataIndex = "Pack_CD";
Columns.Add(clPckCD);
columnNames.Add(clnmPckCD);
#endregion HiddenPackCD_Field
#region HiddenPriceTypeField
Column clPriceType = new Column();
ColumnName clnmPriceType = new ColumnName();
clPriceType.Hidden = true;
clnmPriceType.Text = clPriceType.Text = "PRICE TYPE";
clPriceType.DataIndex = clnmPriceType.DataIndex = "PRICE_TYPE_CD";
Columns.Add(clPriceType);
columnNames.Add(clnmPriceType);
#endregion HiddenPriceTypeField
#region ReadOnlyColumns
foreach (DataColumn c in dt.Columns)
{
if (c.Caption.EndsWith("Name") || c.Caption == "Pack_CD" || c.Caption == "CURRENCY_CD" || c.Caption == "UpdatedNotes" || c.Caption == "NewSelectedDate" || c.Caption == "PRICE_TYPE_CD" || c.Caption == "NewPrices" || c.Caption == "ViewButtons")
{
continue;
}
//Column cl = new Column();
clnm = new ColumnName();
Column numcol = new Column();
switch (c.Caption)
{
case "EFFECTIVEDATE1":
clnm.Text = numcol.Text = "Effective " + editpack.EFFECTIVEDATE1Name;
break;
case "EFFECTIVEDATE2":
clnm.Text = numcol.Text = "Effective " + editpack.EFFECTIVEDATE2Name;
break;
case "EFFECTIVEDATE3":
clnm.Text = numcol.Text = "Effective " + editpack.EFFECTIVEDATE3Name;
break;
}
if (c.Caption == "PRICE_TYPE")
{
clnm.Text = numcol.Text = "Price Type";
numcol.Flex = 2;
}
//if (c.Caption == "NewPrices")
//{
// clnm.Text = numcol.Text = "NewPrices";
// numcol.Flex = 2;
//}
clnm.DataIndex = numcol.DataIndex = c.ColumnName;
Columns.Add(numcol);
columnNames.Add(clnm);
}
#endregion ReadOnlyColumns
#region Component Column
#region GridHeaderDate_NewPrice
ComponentColumn cmpClnm = new ComponentColumn();
DateField dfld = new DateField();
dfld.Listeners.Change.Fn = "NewDateChange";
dfld.MinDate = DateTime.Now.Date;
cmpClnm.HeaderItems.Add(dfld);
cmpClnm.Editor = true;
cmpClnm.Flex = 1;
ColumnName clnmNewDate = new ColumnName();
clnmNewDate.Text = cmpClnm.Text = "New Price";
// clnmNewDate.DataIndex = cmpClnm.DataIndex = dt.Columns[dt.Columns.Count - 7].ColumnName; // old code
clnmNewDate.DataIndex = cmpClnm.DataIndex = dt.Columns[dt.Columns.Count - 2].ColumnName; //new code
List<AbstractComponent> cmps = new List<AbstractComponent>();
cmps.Add(new TextField());
cmpClnm.ToBuilder().Component(cmps);
Columns.Add(cmpClnm);
columnNames.Add(clnmNewDate);
#endregion GridHeaderDate_NewPrice
#region dynamiccomboCurrency
ComponentColumn cmpClnmCurrency = new ComponentColumn();
cmpClnmCurrency.Editor = true;
ColumnName clnmCurr = new ColumnName();
clnmCurr.Text = "";
clnmCurr.DataIndex = cmpClnmCurrency.DataIndex = dt.Columns[1].ColumnName;
List<AbstractComponent> cmpsCombo = new List<AbstractComponent>();
cmpsCombo.Add(new ComboBox()
{
EmptyText = "Select Currency",
Editable = false,
Store = { this.CreateTabularStore(CurrencyDTO, CurrencyDTO.Columns[0].ColumnName) },
ValueField = CurrencyDTO.Columns[0].ColumnName,
DisplayField = CurrencyDTO.Columns[2].ColumnName
});
cmpClnmCurrency.ToBuilder().Component(cmpsCombo);
cmpClnmCurrency.AddListener("Change", "SetDirty");
Columns.Add(cmpClnmCurrency);
columnNames.Add(clnmCurr);
#endregion dynamiccomboCurrency
#region notestextbox
ComponentColumn cmpClnmNotes = new ComponentColumn();
cmpClnmNotes.Editor = true;
cmpClnmNotes.Flex = 3;
ColumnName clnmNote = new ColumnName();
clnmNote.Text = "";
clnmNote.DataIndex = cmpClnmNotes.DataIndex = dt.Columns[dt.Columns.Count - 5].ColumnName;
cmpClnmNotes.Text = "Notes";
List<AbstractComponent> cmpsText = new List<AbstractComponent>();
cmpsText.Add(new TextField()
{
});
cmpClnmNotes.ToBuilder().Component(cmpsText);
Columns.Add(cmpClnmNotes);
columnNames.Add(clnmNote);
#endregion notestextbox
#region Viewnotesbutton
ComponentColumn cmpClnmBtn = new ComponentColumn();
cmpClnmBtn.Editor = false;
cmpClnmBtn.Flex = 1;
ColumnName clnmBtnView = new ColumnName();
clnmBtnView.Text = "";
clnmBtnView.DataIndex = cmpClnmBtn.DataIndex = dt.Columns["ViewButtons"].ColumnName;
List<AbstractComponent> cmpsBtn = new List<AbstractComponent>();
Button cmpsButtn = new Button();
cmpsButtn.Listeners.Click.Fn = "onGroupCommand";
cmpsButtn.Text = "View Notes";
cmpsButtn.Scale = ButtonScale.Medium;
cmpsButtn.CommandName = "viewNotes";
cmpsButtn.Icon = Icon.ApplicationViewDetail;
cmpsBtn.Add(cmpsButtn);
cmpClnmBtn.ToBuilder().Component(cmpsBtn);
Columns.Add(cmpClnmBtn);
columnNames.Add(clnmBtnView);
#endregion Viewnotesbutton
#endregion ComponentColumn
ListCombinePack.Columns = Columns;
#endregion GenerateColumns
#region Generate ModelFields
List<string> Mfields = (from fld in columnNames
select fld.DataIndex).ToList();
ListCombinePack.MFields = Mfields;
#endregion Generate ModelFields
}
ListCombinePack.CommonPackValues = new EditablePackDTO();
ListCombinePack.CommonPackValues.Pack_CD = 5285;
return new Ext.Net.MVC.PartialViewResult
{
ContainerId = "ChildContentContainer",
ViewName = "_TestMethod",
WrapByScriptTag = false,
RenderMode = RenderMode.AddTo,
ClearContainer = true,
//Model = model.FirstOrDefault(),
//ViewData = this.ViewData
Model = ListCombinePack
};
}
Following is my View@model PR.DTO.PackPriceViewModelDTO
@Html.X().ResourceManager()
@{
ViewBag.Title = "TestMethod";
}
@{
var X = Html.X();
}
<script>
var chkDirty = false;
var NewDateChange = function (field, nv, ov) {
var storeSt = Ext.getStore('Store1');
@*Ext.net.Mask.show({ el: App.PackDatesGridView.panel }); *@
Ext.net.Mask.show();
for (var i = 0; i < App.PackDatesGridView.store.getCount() ; i++) {
App.PackDatesGridView.store.getAt(i).set('NewSelectedDate', nv);
}
};
var SetDirty = function () {
chkDirty = true;
};
var PackDetailsCancel = function () {
Ext.net.directRequest({
url: '@Url.Action("Index", "EditPackPrice")',
extraParams: { containerId: "ChildContentContainer" },
ShowMask: true
});
};
var onGroupCommand = function (column, command, group) {
};
</script>
<style>
.labelWith {
width: 200px !important;
}
a.x-tab {
display: none;
text-decoration: none;
}
.x-tab-bar-strip {
display: none !important;
}
</style>
@(
Html.X()
.FormPanel()
.Items(
X.Container()
.Layout(LayoutType.Container)
.DefaultAnchor("100%")
.Items( ********************************************************
X.GridPanel().ID("PackDatesGridView")
.Border(false)
.Cls("x-grid-custom")
.StyleSpec("margin-top:7px;")
.ColumnLines(true)
.EnableColumnHide(false)
.ForceFit(false)
.Layout(LayoutType.Container)
.Scroll(ScrollMode.Horizontal)
.TopBarItem(Html.X().Button().ID("temp").Hidden(true))
.CustomConfig(x =>
{
x.Add(new ConfigItem() { Name = "waitComboBoxStore", Value = "0", Mode = ParameterMode.Raw });
}
)
.Store(
Html.X()
.Store()
.ID("Store1")
.PageSize(Convert.ToInt32(PriceRight.Settings.PropertyReader.GetProperty("GRID_PAGE_SIZE")))
.Model(
Html.X().Model().Fields(((List<string>)Model.MFields).ToArray())
)
.Proxy(
Html.X().AjaxProxy()
.Url(Url.Action("EditSelectedPackPrices", "EditPackPrice"))
.Reader(
Html.X().JsonReader().Root("data")
)
.ExtraParams(x => x.Add(new Parameter() { Name = "selectedPackId", Value = Model.CommonPackValues.Pack_CD.ToString(), Mode = ParameterMode.Raw }))
)
) //End of store
.ColumnModel(
(((IEnumerable<object>)Model.Columns).Cast<ColumnBase>())
)
.BottomBar(
Html.X().PagingToolbar()
.ID("ActivePageBar")
.Height(30)
.HideRefresh(true)
.FirstText(PR.Resources.Common.Common.PagingFirst)
.PrevText(PR.Resources.Common.Common.PagingPrevious)
.NextText(PR.Resources.Common.Common.PagingNext)
.LastText(PR.Resources.Common.Common.PagingLast)
.DisplayMsg(PR.Resources.Common.Common.PagingDisplayMsg)
.AfterPageText(PR.Resources.Common.Common.PaggingAfterPageText)
.BeforePageText(PR.Resources.Common.Common.PaggingBeforePageText)
.EmptyMsg(PR.Resources.Common.Common.PaggingEmptyMsg)
)
.Features(
Html.X().Grouping().HideGroupedHeader(false)
)
.View(
Html.X().GridView().Listeners(events*=>*events.BeforeRefresh.Handler*=*"Ext.net.Mask.show({*el:*this.panel*});"))****
)
)
.Buttons(
Html.X().Button()
.ID("btnSubmit").Scale(ButtonScale.Medium)
.Text(PR.Resources.Master.Master.Save)
.DirectEvents(de =>
{
de.Click.Url = (Url.Action("HandleChanges", "EditPackPrice"));
de.Click.EventMask.ShowMask = true;
de.Click.Timeout = 50000;
de.Click.FormID = "cntPackDetails";
de.Click.ExtraParams.Add(new Parameter
{
Name = "data",
Value = "#{Store1}.getChangedData({skipIdForPhantomRecords: false})",
Mode = ParameterMode.Raw,
Encode = true
});
})
,Html.X().Button().Scale(ButtonScale.Medium)
.ID("btnPackDetailsCancel")
.Text(PR.Resources.Common.Common.Cancel).StyleSpec("margin-right:14px")
.Handler("PackDetailsCancel")
).ButtonAlign(Alignment.Right)
)
And following are the viewModel involved - public class PackPriceViewModelDTO
{
public PackPriceViewModelDTO();
[DataMember]
public List<object> Columns { get; set; }
[DataMember]
public EditablePackDTO CommonPackValues { get; set; }
[DataMember]
public List<EditPack> EditableValues { get; set; }
[DataMember]
public List<string> MFields { get; set; }
}
public class EditPack
{
public EditPack();
[DataMember]
public int CURRENCY_CD { get; set; }
[DataMember]
public string EFFECTIVEDATE1 { get; set; }
[DataMember]
public string EFFECTIVEDATE1Name { get; set; }
[DataMember]
public string EFFECTIVEDATE2 { get; set; }
[DataMember]
public string EFFECTIVEDATE2Name { get; set; }
[DataMember]
public string EFFECTIVEDATE3 { get; set; }
[DataMember]
public string EFFECTIVEDATE3Name { get; set; }
[DataMember]
public DateTime NewSelectedDate { get; set; }
[DataMember]
public int Pack_CD { get; set; }
[DataMember]
public string PRICE_TYPE { get; set; }
[DataMember]
public int PRICE_TYPE_CD { get; set; }
[DataMember]
public string UpdatedNotes { get; set; }
}
public class EditablePackDTO : EditPack
{
public EditablePackDTO();
[DataMember]
public string Country { get; set; }
[DataMember]
public string Discontinued { get; set; }
[DataMember]
public string LastUpdated { get; set; }
[DataMember]
public string LocalName { get; set; }
[DataMember]
public string MarketingAuthority { get; set; }
[DataMember]
public string MarketingStatus { get; set; }
[DataMember]
public DateTime NewDate { get; set; }
[DataMember]
public string ParentCompany { get; set; }
[DataMember]
public string PriceDescription { get; set; }
[DataMember]
public string Region { get; set; }
[DataMember]
public string TheraputicCategory { get; set; }
[DataMember]
public string UnitOfMeasureBasis { get; set; }
}
I am getting following error -
Token is not unique
-------------------
ID = ext.net.global.script.before
TagName = anchor
Match = <#:anchor id='ext.net.global.script.before' />
Kindly provide your inputs.
Last edited by Daniil; May 06, 2014 at 6:55 AM.
Reason: [CLOSED]