This is a migrated thread and some comments may be shown as answers.

toolbar/dropdownlist datasource javascript initilization

1 Answer 58 Views
Toolbar
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 04 Feb 2021, 09:34 PM

     I had a dropdownlist in a page populated like so

@(Html.Kendo().DropDownList()
    .Name("domain")
    .DataTextField("DomainName")
    .DataValueField("DomainName")
    .DataSource(dataSource =>
        dataSource.Read(read =>
            read.Action("GetDomainNames", "MinMax"))
    )
)

 

public JsonResult GetDomainNames()
{
    var dictDomains = new Dictionary<string, string>();
 
    using (var inoAutoEntities = new InoAutoEntities(InoAutoEntitiesHelper.GetEntityString(InoAutoEntitiesHelper.GetCredents())))
    {
        var localSettings = inoAutoEntities
            .Settings
            .Where(item => item.Machine == ".")
            .ToDictionary(item => item.Name);
 
        if (localSettings["UseAutomatedControlService"].Value=="True")
        {
            foreach (var domain in inoAutoEntities.CartSideDomains.GroupBy(item => item.Domain).Select(item => item.Key))
            {
                dictDomains.Add(domain, domain);
            }
 
        }
        else
        {
            var carts = inoAutoEntities.CartControls.Where(item => item.TypeControl == (int)ETypeControl.Owner).ToList();
            foreach (var cartControl in carts)
            {
                if (!dictDomains.ContainsKey(cartControl.Domain))
                {
                    dictDomains.Add(cartControl.Domain, cartControl.Domain);
                }
            }
 
        }
    }
 
    var returnList = dictDomains
        .Keys
        .OrderBy(item => item)
        .ToList();
 
    returnList.Insert(0,"All Domains");
    var result = returnList.Select(item => new DomainModel() {DomainName = item}).AsEnumerable();
    return Json(result,JsonRequestBehavior.AllowGet);
}

 

I wanted to move the dropdownlist to a toolbar but i see that the only way to do that is to use javascript to initialize

what is the syntax that would allow me to populate using a datasource that calls the controller action. I could not find information in the

documentation for toolbar or dropdownlist. any help would be appreciated

@(Html.Kendo().ToolBar()
     .Name("ToolBar")
     .Items(items =>
     {
         items.Add().Template("<div><label>Labels:</label><input id='labels' style='width: 150px;' /></div>").OverflowTemplate("<span></span>");
     }
     )
     )

 

<script type="text/javascript">
    $(document).ready(function () {
        $("#labels").kendoDropDownList({
            dataTextField: "DomainName",
            dataValueField: "DomainName"
        });
    });
 
</script>

 

 

 

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 08 Feb 2021, 04:38 PM

Hello David,

The dataSource configuration of the Kendo UI DropDownList would look like this:

<script type="text/javascript">
    $(document).ready(function () {
        $("#labels").kendoDropDownList({
            dataTextField: "DomainName",
            dataValueField: "DomainName",
            dataSource: {
            	transport: {
            		read: {
            			url: "/MinMax/GetDomainNames",
            			dataType: "json"
            		}
            	}
            }
        });
    });
</script>

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Toolbar
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or