1) I am fetching the data and display the CHIP List using the view bag. First time when page load I want to display all the chip details like
ALL MATHS SCIENCE GEOGRAPHY BIOLOGY
My Controller Code
ViewBag.TVPAllSubject = allSubject.ToList();
ViewBag. datasourceTrainerList = trainersInSectionList;
.cshtml ViewPage Code
<ejs-chiplist id="subject-filterTags" selection="Single" click="subjectFilters">
<e-chips>
@foreach (var product in (List<FilterTagInfo>)ViewBag.TVPAllSubject)
{
<e-chip text="@product.Name" value="@product.FilterTagID" enabled="true"></e-chip>
}
</e-chips>
</ejs-chiplist>
2) On the same page I have a teacher list with the HTML DROPDOWN
< select class="form-control" id="selectTeacher" style="width:30%" onchange="getTeacher(this)" >
<option value="All">All</option>
@foreach (var trainerDetails in ViewBag.datasourceTrainerList)
{
<option value="@trainerDetails.ID">@trainerDetails.Name</option>
}
</select>
3) When I select the particular teacher name I want to update my chip list
For example, If a Teacher named "Mike" is taking lectures on MATHS AND BIOLOGY then I want to update my chip-list using JAVASCRIPT and generate a new chip list with the name MATHS and BIOLOGY including the property id="subject-filterTags" selection="Single" click="subjectFilters", working same as when page gets loaded.
.
4) Down below I have tried the code but it is now working.
function getTeacher(selectObject) {
if (document.getElementById("selectTeacher").value != "All") {
document.getElementById('subject-filterTags').remove([0]);
document.getElementById('subject-filterTags').ej2_instances[0] = '@ViewBag.TVPFilterTags';
}
}
<ejs-chiplist selection="Single">
<e-chips>
@foreach (var item in ViewBag.dataSource)
{
<e-chip text=@item cssClass=@item enabled="true"></e-chip>
}
</e-chips>
</ejs-chiplist>
<select name="cars" id="drop" onchange="getTeacherVideo(this)">
. . .
</select> <script>
function getTeacherVideo(args) {
if (value == "Mike" || value == "Duke") {
document.getElementsByClassName('MATHS')[0].style.visibility = "hidden";
document.getElementsByClassName('SCIENCE')[0].style.visibility = "hidden";
document.getElementsByClassName('ALL')[0].style.visibility = "hidden";
document.getElementsByClassName('BIOLOGY')[0].style.visibility = "visible";
document.getElementsByClassName('GEOGRAPHY')[0].style.visibility = "visible";
}
else if (value == "John") {
document.getElementsByClassName('MATHS')[0].style.visibility = "visible";
document.getElementsByClassName('SCIENCE')[0].style.visibility = "visible";
document.getElementsByClassName('BIOLOGY')[0].style.visibility = "hidden";
document.getElementsByClassName('GEOGRAPHY')[0].style.visibility = "hidden";
}
else {
chip.refresh();
}
}
</script> |