Hi,
i am generating a grid with Multi select Combo box in it using a column template.
i am able to select the multiselect combo values and able the read the selected items.
i have one more requirement, i have to select/check the values of multiselect combo values dynamically through JQuery.
Please help me how to do that? Below is the code.
This is the code of a grid, where i am creating Multiselect combo box in one of the cell.
var dataSource = new kendo.data.DataSource({
transport: {
read: function (e) {
e.success(result);
},
update: function (e) {
e.success();
},
create: function (e) {
var item = e.result;
item.Id = result.length + 1;
e.success(item);
}
},
schema: {
model: {
id: "SNO",
fields: {
SNO: { type: "int" },
PassengerStatus: { type: "int" },
ElevatorShutdown: { type: "bool" },
TrappedPassenger: { type: "bool" },
UnitControllerStatus: { type: "bool" },
ActiveVoiceVideoCall: { type: "bool" },
controllerStatus: { type: "bool" },
Delay: { type: "int" }
}
}
}
});
//my own
$("#UnitgridPerf").kendoGrid({
dataSource: dataSource,
editable: { createAt: "bottom" },
dataBound: function (e) {
createMultiSelect(e);
},
// pageable: true,
columns: [
{
field: "SNO", width: "50px", editable: function (arg) { return true; }, headerAttributes: {
}
},
{
field: "PassengerStatus", title: "PD", editable: function (arg) { return true; }, width: "40px"
, headerAttributes: {
}
},
{
field: "ElevatorShutdown", title: "OOS", editable: function (arg) { return true; }, width: "50px"
, headerAttributes: {
}
},
{
field: "TrappedPassenger", title: "TP", editable: function (arg) { return true; }, width: "50px"
, headerAttributes: {
}
},
{
field: "UnitControllerStatus", title: "REM", width: "170px", editable: function (arg) { return false; }, template: "<select class='Multiselectval'></select>"
, headerAttributes: {
}
},
{
field: "ActiveVoiceVideoCall", title: "VC", width: "50px", editable: function (arg) { return true; }
, headerAttributes: {
}
},
{
field: "controllerStatus", title: "CTRL", width: "50px", editable: function (arg) { return true; }
, headerAttributes: {
}
},
{
field: "Delay", editable: function (arg) { return true; }, width: "50px"
, headerAttributes: {
}
},
{ command: "destroy", title: "", width: "40px" }
],
});
// code to add Multi Select Combo box to Kendo Grid Cell
var checkInputs = function (elements) {
elements.each(function () {
var element = $(this);
var input = element.children("input");
input.prop("checked", element.hasClass("k-state-selected"));
});
};
// create MultiSelect from select HTML element
function createMultiSelect(e) {
$(".Multiselectval").append(new Option('ALARM_HANDLER_TASK', enumRemComponents.ALARM_HANDLER_TASK));
$(".Multiselectval").append(new Option('PERFORMANCE_TASK', enumRemComponents.PERFORMANCE_TASK));
$(".Multiselectval").append(new Option('REM_DEVICE_AUTH_TASK', enumRemComponents.REM_DEVICE_AUTH_TASK));
$(".Multiselectval").append(new Option('SERIAL_LINK_TASK', enumRemComponents.SERIAL_LINK_TASK));
$(".Multiselectval").append(new Option('STATE_MACHINE_TASK', enumRemComponents.STATE_MACHINE_TASK));
$(".Multiselectval").append(new Option('UNKNOWN_TASK', enumRemComponents.UNKNOWN_TASK));
var grid = e.sender;
required = $(".Multiselectval").kendoMultiSelect({
itemTemplate: "#:data.text# <input type='checkbox'/>",
autoClose: false,
dataBound: function () {
var items = this.ul.find("li");
setTimeout(function () {
checkInputs(items);
});
},
change: function () {
var items = this.ul.find("li");
checkInputs(items);
}
}).data("kendoMultiSelect");
}
The above code is working properly.
Now i want to select the Multiselect combo values based on the data i got from Database., below is the code i am trying for that, but i am unable to make the values selected.
var grid = $('#UnitgridPerf').data("kendoGrid");
grid.dataSource.data(result);
for (var j = 0; j < UnitPattern.length; j++) {
if (PatternName == UnitPattern[j].PatternName) {
for (var i = 0; i < UnitPattern[j].Devicestatus[0].ComponentStatus.length; i++) {
var gridRows = grid.tbody.find('tr');
var row = $(gridRows[i]);
var rid = row.find('.Multiselectval');
alert(rid[1][UnitPattern[j].Devicestatus[0].ComponentStatus[i].Component].value);
rid[1][UnitPattern[j].DeviceStatus[0].ComponentStatus[i].Component].value.checked;
// $('.rid option[value=' + UnitPattern[j].DeviceStatus[0].ComponentStatus[i].Component + ']').attr('selected', true);
}
}
Please help on this.