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

Remove items based on selected value

3 Answers 901 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 23 Sep 2014, 10:19 AM
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

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 25 Sep 2014, 09:15 AM
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!
 
0
Chase
Top achievements
Rank 1
answered on 14 Apr 2015, 10:04 AM

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

-1
Georgi Krustev
Telerik team
answered on 16 Apr 2015, 07:13 AM
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!
 
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
commented on 08 Aug 2022, 04:52 PM

The link mentioned above is dead.
Martin
Telerik team
commented on 10 Aug 2022, 02:09 PM

Hi, Lee,

The post is from 2015 and the video links appears to be deleted after such a long period of time. If you are experiencing any difficulties or have any questions regarding the topic of this thread, feel free to ask. Otherwise, kindly open a new support ticket.

Tags
MultiSelect
Asked by
Jako
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Chase
Top achievements
Rank 1
Share this question
or