PDA

View Full Version : [CLOSED] Loop through TemplateHtml in RowExpander



matrixwebtech
Aug 20, 2014, 2:02 PM
I am take http://mvc.ext.net/#/GridPanel_RowExpander/Remote_Mode/ as an example .

and change GetData() function like bellow for multiple return value and show in RowExpander's TemplateHtml ,currently in example it will return single value display,How I display multiple records after expand?





public ActionResult GetData(string company, int index)
{

var Questions = new List<jr>
{
new jr {company = "s1", index = "Q1,Q2",time=DateTime.Now.ToLongTimeString()},
new jr {company = "s2", index = "Q1,Q2,Q3",time=DateTime.Now.ToLongTimeString()},
new jr {company = "s3", index = "Q1,Q2,Q4",time=DateTime.Now.ToLongTimeString()},
new jr {company = "s4", index = "Q1,Q2,Q5",time=DateTime.Now.ToLongTimeString()},
};

JsonResult _jr = new JsonResult();
_jr.Data = Questions;
return _jr;
}


RowExpander inside grid.where I add the loop in TemplateHtml


.Plugins(
Html.X().RowExpander()
.Loader(Html.X().ComponentLoader()
.Mode(LoadMode.Data)
.Url(Url.Action("GetData"))
.LoadMask(mask => mask.ShowMask = true)
.Params(
new
{
company = JRawValue.From("this.record.data['company']"),
index = JRawValue.From("this.grid.store.indexOf(this.record)")
}
)
)
.TemplateHtml(@<text>
<span class="template">
Company: {company}, Row №: {index}, Server Date: {time}
</span>
</text>)
)

Daniil
Aug 21, 2014, 9:41 AM
Hi @matrixwebtech,

I would recommend to investigate the docs for XTemplate.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.XTemplate

Specifically, to iterate an array, please use:

<tpl for=".">
...template for each item goes here...
</tpl>

Regarding to the example that you mentioned, you could define such a template:

@<text>
<tpl for=".">
<div class="template">Company: {company}, Row #: {index}, Server Date: {time}</div>
</tpl>
</text>
and return such the data:

public ActionResult GetData(string company, int index)
{
return this.Json(new object[]
{
new
{
company = company + "0",
index = index,
time = DateTime.Now.ToLongTimeString()
},
new
{
company = company + "1",
index = index + 1,
time = DateTime.Now.ToLongTimeString()
},
new
{
company = company + "2",
index = index + 2,
time = DateTime.Now.ToLongTimeString()
}
});
}

matrixwebtech
Aug 21, 2014, 10:10 AM
Hi daniil thanks for your help.

I am very much surprised to look that a for loop can be done like this.relay Ext.net made things easy and simple.Thanks to all EXT.Net team members.