PDA

View Full Version : [CLOSED] ComboBox have two fields in display



registrator
Apr 01, 2015, 11:36 AM
For a combo box:


X.ComboBoxFor(m => m.GLOBAL_TAX_CODE).FieldLabel("Tax Code").LabelWidth(80).DisplayField("ComboDisplay").ValueField("TaxCodeID")
.ListConfig(Html.X().BoundList()
.ItemTpl(Html.X().XTemplate()
.Html(@<text>
<div class="list-item">
<h3>{Name} - Rate: {RATE}%</h3>
{DESCRIPTION}
</div>
</text>)
)
)
.Store(X.Store()
.ID("TaxCodeComboStore")
.AutoLoad(true)
.Model(
X.Model()
.Name("TaxCodeCombo")
.IDProperty("TaxCodeID")
.Fields(
X.ModelField()
.Name("Name")
.Type(ModelFieldType.String),
X.ModelField()
.Name("DESCRIPTION")
.Type(ModelFieldType.String),
X.ModelField()
.Name("RATE")
.Type(ModelFieldType.Float)
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetList", "List", new { area = "TaxCode" }))
.Reader(Html.X().JsonReader().Root("data"))
)
)



can I have a DisplayField setting displaying two model fields instead only one?

Thank you

Daniil
Apr 01, 2015, 9:27 PM
Hi @registrator,

I guess you need to use a ComboBox's DisplayTpl.

A possible value could be:

<tpl for=".">
{Name} - Rate: {RATE}
</tpl>

registrator
Apr 02, 2015, 10:09 AM
How would this look like for the MVC razor view please?

Thnx

Daniil
Apr 02, 2015, 10:13 AM
It would look similar to what you defined for .ItemTpl.

registrator
Apr 02, 2015, 11:50 AM
I have removed the Display Field definition and added the diplay template but when clicking and selecting a value fromt he combo nothing is displayed in the field.



X.ComboBoxFor(m => m.GLOBAL_TAX_CODE).FieldLabel("Tax Code").LabelWidth(80).ValueField("TaxCodeID")
.AllowBlank(true)
.ListConfig(Html.X().BoundList()
.ItemTpl(Html.X().XTemplate()
.Html(@<text>
<div class="list-item">
<h3>{Name} - Rate: {RATE}%</h3>
{DESCRIPTION}
</div>
</text>)
)
)
.DisplayTpl(Html.X().XTemplate()
.Html(@<text>
{Name} {RATE}
</text>)
)
.Store(X.Store()
.ID("TaxCodeComboStore")
.AutoLoad(true)
.Model(
X.Model()
.Name("TaxCodeCombo")
.IDProperty("TaxCodeID")
.Fields(
X.ModelField()
.Name("Name")
.Type(ModelFieldType.String),
X.ModelField()
.Name("DESCRIPTION")
.Type(ModelFieldType.String),
X.ModelField()
.Name("RATE")
.Type(ModelFieldType.Float)
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetList", "List", new { area = "TaxCode" }))
.Reader(Html.X().JsonReader().Root("data"))
)
)

Daniil
Apr 02, 2015, 12:02 PM
There must be a <tpl for="."> as it is in my example.

registrator
Apr 02, 2015, 12:17 PM
OK. Very good. Thank you



.DisplayTpl(Html.X().XTemplate()
.Html(@<text>
<tpl for=".">
{Name} - Rate: {RATE}
</tpl>
</text>)
)