hello!!
I'm trying to create a dropdownlist mutliselect.
in fact I have two dropdownlist that I consider as a parent and the other as a child.
when I select a parent in the first dropdownlist, a list of child appears in the other dropdownlist. You can choose several child for one parent. For this I used checkbox ,creating a template as follows:
------
<script type="text/x-kendo-tmpl" id="myTemplate">
#if (ID){#
<div class="item click" data="${ID}">
<input id ="${ID}" type="checkbox" class="click xxx_${ID}" value="${ID}" />
<span class="checkbox">#:Name#</span>
</div>
#}#
</script>
--------
my dropdownlist are:
-----
var dropdownlistChapterParent =$('#IDChapterTemplates_' + e + '').each(function () {
var combobox = $(this);
var dropdownlistChapterParent= combobox.kendoDropDownList({
optionLabel: " ",
dataTextField: "Name",
dataValueField: "ID",
dataSource: {
data: Chapters
},
change: function () {
var DataItem = combobox.data("kendoDropDownList").dataItem();
combobox.parent().find('#ChapterTemplateID_'+e+'').val(DataItem.ID);
parentid=DataItem.ID;
$.ajax({
type: 'GET',
template: kendo.template($("#myTemplate").html()),
url: '@Url.Action("GetChapterTemplatefils","Reports")',
data: { chaptertypeid: parentid },
success: function (response) {
$('#IDchapterTemplatefils_'+str1+'').data('kendoDropDownList').dataSource.data(response);
}
});
}
}).data("kendoDropDownList");
dropdownlistChapterParent.select(function(DataItem) {
return DataItem.ID == value.TemplateID;
});
});
var dropdownlistChapterChild=$('#IDchapterTemplatefils_' + e + '').each(function () {
var combobox = $(this);
combobox.kendoDropDownList({
optionLabel: " ",
dataTextField: "Name",
dataValueField: "ID",
template: kendo.template($("#myTemplate").html()),
dataSource: {
transport: {
read: {
url: '@Url.Action("GetChapterTemplatefils","Reports")?chaptertypeid=' + value.TemplateID
}
},
schema: {
model: {
ID: "ID",
Name: "NAME"
}
}
},
change: function () {
var DataItem = combobox.data("kendoDropDownList").dataItem();
combobox.parent().parent().find('#ChapterTemplatefilsID_' + e + '').val(DataItem.ID);
}
});
}).data("kendoDropDownList");
-----------------------
-----------
for example, if I am having parent1 and child11 child12 child13 like child (for parent1). I select clihd11 and i save. After i I am considering an edition. Normally child11 must be checked. I check child12. I have now child11 child12 .
my questions are:
1-
var child=value.ChapterChild;
alert("Press ok!");
var h = 0;
if (child.length>= 1) {
for(h=0;h<child.length;h++){
$('.xxx_'+child[h]).attr('checked','checked');
}
}
I can not remove "alert("Press ok!");" because when I click "edit" child11 is not checked?????????
2- when I checked child11 and child12 and if I get the values ​​that are checked, I have child11 child11 child12. That's false beacause I 'll have child11 child12.
II get the value of checkbox as follows:
---
var checkboxes = $("#IDchapterTemplatefils_" + j + "-list .click:checked");
var values = [];
console.log(checkboxes);
$(checkboxes).each(function(i, elt){
values.push($(elt).val());
});
----
and when I debug my project with firebug. I have two #IDchapterTemplatefils_1-list as id .
thank you for help
I'm trying to create a dropdownlist mutliselect.
in fact I have two dropdownlist that I consider as a parent and the other as a child.
when I select a parent in the first dropdownlist, a list of child appears in the other dropdownlist. You can choose several child for one parent. For this I used checkbox ,creating a template as follows:
------
<script type="text/x-kendo-tmpl" id="myTemplate">
#if (ID){#
<div class="item click" data="${ID}">
<input id ="${ID}" type="checkbox" class="click xxx_${ID}" value="${ID}" />
<span class="checkbox">#:Name#</span>
</div>
#}#
</script>
--------
my dropdownlist are:
-----
var dropdownlistChapterParent =$('#IDChapterTemplates_' + e + '').each(function () {
var combobox = $(this);
var dropdownlistChapterParent= combobox.kendoDropDownList({
optionLabel: " ",
dataTextField: "Name",
dataValueField: "ID",
dataSource: {
data: Chapters
},
change: function () {
var DataItem = combobox.data("kendoDropDownList").dataItem();
combobox.parent().find('#ChapterTemplateID_'+e+'').val(DataItem.ID);
parentid=DataItem.ID;
$.ajax({
type: 'GET',
template: kendo.template($("#myTemplate").html()),
url: '@Url.Action("GetChapterTemplatefils","Reports")',
data: { chaptertypeid: parentid },
success: function (response) {
$('#IDchapterTemplatefils_'+str1+'').data('kendoDropDownList').dataSource.data(response);
}
});
}
}).data("kendoDropDownList");
dropdownlistChapterParent.select(function(DataItem) {
return DataItem.ID == value.TemplateID;
});
});
var dropdownlistChapterChild=$('#IDchapterTemplatefils_' + e + '').each(function () {
var combobox = $(this);
combobox.kendoDropDownList({
optionLabel: " ",
dataTextField: "Name",
dataValueField: "ID",
template: kendo.template($("#myTemplate").html()),
dataSource: {
transport: {
read: {
url: '@Url.Action("GetChapterTemplatefils","Reports")?chaptertypeid=' + value.TemplateID
}
},
schema: {
model: {
ID: "ID",
Name: "NAME"
}
}
},
change: function () {
var DataItem = combobox.data("kendoDropDownList").dataItem();
combobox.parent().parent().find('#ChapterTemplatefilsID_' + e + '').val(DataItem.ID);
}
});
}).data("kendoDropDownList");
-----------------------
-----------
for example, if I am having parent1 and child11 child12 child13 like child (for parent1). I select clihd11 and i save. After i I am considering an edition. Normally child11 must be checked. I check child12. I have now child11 child12 .
my questions are:
1-
var child=value.ChapterChild;
alert("Press ok!");
var h = 0;
if (child.length>= 1) {
for(h=0;h<child.length;h++){
$('.xxx_'+child[h]).attr('checked','checked');
}
}
I can not remove "alert("Press ok!");" because when I click "edit" child11 is not checked?????????
2- when I checked child11 and child12 and if I get the values ​​that are checked, I have child11 child11 child12. That's false beacause I 'll have child11 child12.
II get the value of checkbox as follows:
---
var checkboxes = $("#IDchapterTemplatefils_" + j + "-list .click:checked");
var values = [];
console.log(checkboxes);
$(checkboxes).each(function(i, elt){
values.push($(elt).val());
});
----
and when I debug my project with firebug. I have two #IDchapterTemplatefils_1-list as id .
thank you for help