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

2 posts, 0 answers
  1. Mike
    Mike avatar
    16 posts
    Member since:
    Feb 2014

    Posted 23 Jan 2015 Link to this post

    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" })

  2. Mike
    Mike avatar
    16 posts
    Member since:
    Feb 2014

    Posted 23 Jan 2015 in reply to Mike Link to this post

    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.

  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top