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

Trigger select event manully pass item and item value to event handler

1 Answer 1041 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 23 Jan 2015, 03:35 PM
I set the selected item using the first code block below. But I need to pass the item and items value to the selected event function. Which is the second code block below.  i also included the code for the Dropdownlist, the third code block.  How do I do this?  Thanks
function onIncDataBound() {
var dropdownlist = $("#IncludeExclude").data("kendoDropDownList");
if (dropdownlist.dataSource.data().length == 1) {
debugger;
var items = $("li.k-state-selected", $("#IncludeExclude-list"));
dropdownlist.trigger("select", { item: items, value: dropdownlist.text() });
}
}
function onInExSelect(e) {
        debugger;
        var projSq = '@Model.Project.ProjSq';
        var typeDol = $('#type').val();
        var county = $('#county').val();
        var dataItem = this.dataItem(e.item);
        var incExc = dataItem.Value;
        var Url = '@Url.Action("GetDecision", "Shared")';
        $.ajax({
            url: Url,
            type: 'GET',
            dataType: 'HTML',
            data: { cnty: county, projSq: projSq, includeExclude: incExc, type: typeDol }
        })
@(Html.Kendo().DropDownListFor(d => d.RequestFlatten.IncludeExclude)
.Name("IncludeExclude")
.HtmlAttributes(new { style = "width:450px" })
.OptionLabel("Select Include/Exclude")
.DataTextField("Description")
.DataValueField("Value")
.CascadeFromField("Type")
.Events(e => e.Select("onInExSelect").DataBound("onIncDataBound"))
.CascadeFrom("FdolTypeCode")
.AutoBind(false)
.Enable(false)
.DataSource(ds => ds.Read(r => r.Action("GetIncludeExcludeByCountyAndType", "Shared").Data("filterIncludeEx"))
.ServerFiltering(true)))
@Html.HiddenFor(h => h.RequestFlatten.IncludeExclude, new { id = "incExc" })

1 Answer, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 23 Jan 2015, 04:37 PM
i was able to get this to work by doing the following.
  1. OnDatabound event, I set the select to select(1);
    function onIncDataBound() {
            var dropdownlist = $("#IncludeExclude").data("kendoDropDownList");
            if (dropdownlist.dataSource.data().length == 1) {
                dropdownlist.select(1);
            }
        }
  2. OnCascade event, which is fired after changing the selected value in step 1. I put the code I needed to process.
    function onIncCascade(e) {
            var projSq = '@Model.Project.ProjSq';
            var typeDol = $('#type').val();
            var county = $('#county').val();
            var dataItem = this.dataItem(e.item);
            var incExc = dataItem.Value;
            var Url = '@Url.Action("GetDecision", "Shared")';
            $.ajax({
                url: Url,
                type: 'GET',
                dataType: 'HTML',
                data: { cnty: county, projSq: projSq, includeExclude: incExc, type: typeDol }
            })
        .done(function (data) {
            $('#DecisionDiv').html(data);
        });

This worked great.  But I have duplicate code at this time in two different events. will need to refactor this later. but for know it works. If someone knows of a better way please share.

Tags
DropDownList
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Share this question
or