PDA

View Full Version : [CLOSED] Combobox with all icon MVC



matrixwebtech
Sep 27, 2014, 5:43 AM
Hi,
How do I populate a combobox with all EXT.Net Icons from code behind,I am unable to find example or any forum post.please help.

I read http://forums.ext.net/showthread.php?20802-List-of-Icons and http://forums.ext.net/showthread.php?9895-Combobox-with-Icon and try some thing bellow.but not working


Html.X().ComboBox()
.ID("ComboBoxAllIcons")
.Editable(false)
.QueryMode(DataLoadMode.Local)
.TriggerAction(TriggerAction.All)
.EmptyText("Select a country")
.DisplayField("name")
.ValueField("name")
.FieldLabel("Country")

.ForceSelection(true)

.Store(Html.X().Store()
.ID("strore1")

.Model(Html.X().Model()
// .IDProperty("Id")
.Fields(

Html.X().ModelField().Name("iconCls").Type(ModelFieldType.String),
Html.X().ModelField().Name("name").Type(ModelFieldType.String)
)

)


)

.ListConfig(Html.X().BoundList()
.ItemTpl(Html.X().XTemplate()
.Html(@<tpl for=".">
<div class="x-combo-list-item icon-combo-item {iconCls}">
{name}
</div>
</tpl>)
)
)


public ActionResult Index()
{

List<string> s= Enum.GetNames(typeof(Icon)).ToList<string>();
var st = X.GetCmp<Store>("strore1");
st.LoadData(s);
return View();
}

geoffrey.mcgill
Sep 27, 2014, 6:47 AM
http://examples2.ext.net/#/Miscellaneous/Icon/Icon_Summary/

Look at the source code for that sample and it should help you with your sample.

Once you have a sample working, please post here in the forums to share with others.

matrixwebtech
Sep 27, 2014, 6:54 AM
Hi,
I already have your mentioned link,but the problem is data not load in combobox,can you please assist me what I need to do ?

geoffrey.mcgill
Sep 27, 2014, 7:43 AM
You can review the generated JavaScript, and try to work out what's going wrong.

Tools such as Firefox + Firebug can be very helpful with debugging JavaScript.

How about first trying to get the sample working with a static array of objects. Once you have that working, then proceed to generating a List of Enum values.

matrixwebtech
Jan 21, 2015, 10:58 AM
After a long time I post in this thread.I go through again http://examples2.ext.net/#/Form/ComboBox/IconCombo/ but not understand how I do this in MVC. Is there any way to get all icons in a list and then bind with combo box? please help.

matrixwebtech
Jan 22, 2015, 4:42 PM
can any body give me some idea on this?

Daniil
Jan 23, 2015, 11:10 AM
but not understand how I do this in MVC

Could you, please, formulate some specific statements and questions what exactly problem you are facing implementing that example in MVC? You've already built a lot of great stuff in MVC with Ext.NET, so I am not sure how exactly I could help in this case.


Is there any way to get all icons in a list and then bind with combo box? please help.

Yes, there should be a way. As far as I can see Geoffrey said a couple of tips. Please clarify have you tried any? What is the result?

matrixwebtech
Jan 27, 2015, 7:20 AM
Hi,
I do bellow code

View


<div>
@X.ResourceManager()
@(Html.X().ComboBox()
.ID("ComboBoxAllIcons")
.Editable(false)
.QueryMode(DataLoadMode.Local)
.TriggerAction(TriggerAction.All)
.EmptyText("Select a country")
.DisplayField("name")
.ValueField("name")
.FieldLabel("Country")

.ForceSelection(true)

.Store(Html.X().Store()
.ID("strore1")

.Model(Html.X().Model()
// .IDProperty("Id")
.Fields(

Html.X().ModelField().Name("iconCls").Type(ModelFieldType.String),
Html.X().ModelField().Name("name").Type(ModelFieldType.String)
)

)
.Proxy(X.AjaxProxy()
.Url(Url.Action("geticons")))

)

.ListConfig(Html.X().BoundList()
.ItemTpl(Html.X().XTemplate()
.Html(@<tpl for=".">
<div class="thumb-wrap" id="{name}">
<div class="thumb"><img src="{iconCls}" title="{name}">&nbsp;{name}</div>
</div>
</tpl>)
)
)
)
</div>

Controller


public ActionResult Index()
{


return View();
}

public StoreResult geticons()
{

List<string> icons = Enum.GetNames(typeof(Icon)).ToList<string>();

icons.Remove("None");

List<object> data = new List<object>(icons.Count);

icons.ForEach(icon => data.Add(
new
{
name = icon,
iconCls = GetIconClassName(((Icon)Enum.Parse(typeof(Icon), icon)))
}
));


return this.Store(data);

}

public string GetIconClassName(Icon icon)
{
ResourceManager.RegisterGlobalIcon(icon);
return ResourceManager.GetIconClassName(icon);
}

but not working ,only one Item add to combo box without name and image.can you please correct me?

geoffrey.mcgill
Jan 27, 2015, 2:51 PM
Hello,

If you view the html source of this page, is every single icon location rendered? If you are using ResourceManager.RegisterGlobalIcon, then I think that will add a path config for each icon directly into the page source. There are 1700+ icons, so that is going to add a lot of bloat to your page.

I think you might want to investigate a different approach.