Skip to content

Commit 06ae3fe

Browse files
committed
feat: add Cascading MultiSelect example
1 parent 134dd44 commit 06ae3fe

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.Rendering;
3+
using System;
4+
using System.Linq;
5+
6+
namespace Telerik.Examples.Mvc.Controllers.MultiSelect
7+
{
8+
public class Cascading_MultiSelectController : Controller
9+
{
10+
public IActionResult Cascading_MultiSelect()
11+
{
12+
return View();
13+
}
14+
public IActionResult ReadParent()
15+
{
16+
var results = Enumerable.Range(1, 10).Select(i => new SelectListItem
17+
{
18+
Text = "Super cool item " + i,
19+
Value = i.ToString()
20+
});
21+
return Json(results);
22+
}
23+
24+
public IActionResult ReadChild()
25+
{
26+
var selectionList = this.Request.Form.ToList().Select(item => (Int32.Parse(item.Value)));
27+
var listMax = selectionList.Max(value => value);
28+
var results = Enumerable.Range(1, listMax).Select(i => new SelectListItem
29+
{
30+
Text = "Nice item " + i,
31+
Value = i.ToString()
32+
});
33+
return Json(results);
34+
}
35+
}
36+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<h4>Parent MultiSelect</h4>
2+
3+
4+
@(Html.Kendo().MultiSelect()
5+
.Name("parent")
6+
.Placeholder("Select ...")
7+
.DataTextField("Text")
8+
.DataValueField("Value")
9+
.DataSource(source =>
10+
{
11+
source.Read(read => read.Action("ReadParent", "Cascading_MultiSelect"));
12+
})
13+
.AutoClose(false)
14+
.Events(e => e.Change("onChange"))
15+
)
16+
17+
<br />
18+
<br />
19+
<h4>Child MultiSelect</h4>
20+
21+
@(Html.Kendo().MultiSelect()
22+
.Name("child")
23+
.AutoBind(false)
24+
.Enable(false)
25+
.Placeholder("Select ...")
26+
.DataTextField("Text")
27+
.DataValueField("Value")
28+
.DataSource(source =>
29+
{
30+
source.Read(read => read.Action("ReadChild", "Cascading_MultiSelect").Data("parentData").Type(HttpVerbs.Post));
31+
})
32+
)
33+
34+
<script>
35+
36+
function onChange(e) {
37+
var child = $("#child").data("kendoMultiSelect");
38+
if (e.sender.value().length > 0) {
39+
child.enable(true);
40+
child.dataSource.read();
41+
} else {
42+
child.enable(false);
43+
}
44+
}
45+
function parentData() {
46+
var parent = $("#parent").data("kendoMultiSelect");
47+
var value = parent.value();
48+
var additionalData = Object.assign({}, value);
49+
return additionalData;
50+
}
51+
</script>

0 commit comments

Comments
 (0)