Remove items based on selected value

4 posts, 0 answers
  1. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 23 Sep 2014 Link to this post

    Hi everyone

    I have a multiselect, its preloaded with "All", when I select a new option, it removes the all item from the select. What I want to do is add a section so that when the user selects "All" again, it clears all the other options except for all.

    I have the following code, my dataItem.Value keeps giving me "undefined" I have changed to .value as well, no luck.
    @(Html.Kendo().MultiSelectFor(m => m.ReportCriteria.ProductClassList)
          .Name("ReportCriteria.ProductClassList")
          .DataTextField("ProductClassDescription")
          .DataValueField("ProductClassCode")
          .Events(e => e.Select("onSelect"))
          .AutoBind(true)
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("ProductClassList", "Dashboard")
                  .Data("sendProductClassText");
              });
              source.ServerFiltering(true);
          })
    )
    Here is the JS
    function onSelect(e) {
        var allSelect = ["All"];
        var multi = $("#ReportCriteria_ProductClassList").data("kendoMultiSelect");
     
        var dataItem = this.dataSource.view()[e.item.index()];
     
        alert(dataItem.Value);
     
        if (dataItem.Value == "All")
        {
            multi.value(["All"]);
        }
     
        if (multi.value().indexOf("All") > -1)
        {
            var values = multi.value().slice();
            values = $.grep(values, function (a) {
                return $.inArray(a, allSelect) == -1;
            });
     
            multi.dataSource.filter({});
            multi.value(values);
        }
    }
    Any ideas what I am doing wrong?

    Thank you
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 25 Sep 2014 Link to this post

    Hi Jako,

    The dataItem.Value is undefined, because the value field defined in your configuration is ProductClassCode. ​If want to check the value then you will need to check the value field property:
    dataItem.ProductClassCode
    Here is a Dojo demo based on your approach.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Chase
    Chase avatar
    3 posts
    Member since:
    Apr 2014

    Posted 14 Apr 2015 in reply to Georgi Krustev Link to this post

    Hello Georgi, 
    I don't think this works for the Q1 2015 release. Can you provide guidance how to achieve the same results for the new release?

      Best, 
    -Chase

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 16 Apr 2015 Link to this post

    Hello Chase,

    I believe that the demo works just fine with the latest official release of Kendo UI (2015.1.408). Here is a screencast that depicts this.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready