Hi,
I've added code so that the combobox datasource reads from a cached set of data initially, then makes a server call if more than a couple of letters are typed in and refreshes the data (sort of a combined Combobox and Autoselect):
<img height="20px" width="20px" src="ASSETS/IMAGES/jumpArrow.svg" id="jumpMovie" /><input id="movies"/><br />
$("#movies").kendoComboBox({
dataTextField: "Display",
dataValueField: "CPSWGUID",
select: onSelect,
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: function (operation) {
var url = "/api/Lookup/2/";
var cashedData = localStorage.getItem("moviesData");
//alert($(this).attr('id'));
var combobox = $("#movies").data("kendoComboBox");
if (cashedData === null) {
$.getJSON(url, function (json) {
localStorage.setItem("moviesData", JSON.stringify(json));
operation.success(json);
});
}
else {
if (combobox.text() == '' || combobox.text() == undefined) {
var retval = $.parseJSON(cashedData);
operation.success(retval);
} else {
$.getJSON(url, { searchvalue: combobox.text() }, function (json) {
operation.success(json);
});
}
}
}
},
schema: { data: "Table" }
}),
ShowToggleImage: false,
headerTemplate: '<div class="dropdown-header">' +
'<span class="k-widget k-header"><a onclick="addNewRecord(\'movies\')">Add New</a></span>' +
'<span class="k-widget k-header"><a onclick="clearComboVal(\'movies\')">Clear</a></span></div>',
template: '<span class="k-state-default"><h3>#: data.Display #</h3><p>#: data.Display2 #</p></span>',
});
var combobox = $("#movies").data("kendoComboBox");
combobox.input.keyup(function (event) {
if (combobox.text().length == 0) {
combobox.dataSource.read();
combobox.value('');
} else if (combobox.text().length >= 3) {
if (event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13) {
combobox.dataSource.read();
}
}
});
$(document).off('click', '#jumpMovie').on('click', '#jumpMovie', function () {
if (combobox.value() != '') {
alert(combobox.value());
}
});
function clearComboVal(ctrlname) {
var me = $('#' + ctrlname).data("kendoComboBox");
me.value('');
}
function addNewRecord(ctrlname) {
var me = $('#' + ctrlname).data("kendoComboBox");
me.dataSource.add({ CPSWGUID: "3FB46FDE-E333-424B-8690-2B4D9EC20090", Display: "Record, New" });
me.value("3FB46FDE-E333-424B-8690-2B4D9EC20090");
}
This is something I'm hoping to use as a standalone control several places in the application and would ideally also like to have it embedded in grids. My questions are:
1. Is it possible to wrap something like this in an editor in a grid so that the datasources are individual to the cells being looked at?
2. How would I refer to the data("kendoCombobox") in the datasource of the combobox in a generic way where I wouldn't have to specify the id of control itself? This would probably be necessary for anywhere that "movies" is explicitly stated.
Thanks for your help.
I've added code so that the combobox datasource reads from a cached set of data initially, then makes a server call if more than a couple of letters are typed in and refreshes the data (sort of a combined Combobox and Autoselect):
<img height="20px" width="20px" src="ASSETS/IMAGES/jumpArrow.svg" id="jumpMovie" /><input id="movies"/><br />
$("#movies").kendoComboBox({
dataTextField: "Display",
dataValueField: "CPSWGUID",
select: onSelect,
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: function (operation) {
var url = "/api/Lookup/2/";
var cashedData = localStorage.getItem("moviesData");
//alert($(this).attr('id'));
var combobox = $("#movies").data("kendoComboBox");
if (cashedData === null) {
$.getJSON(url, function (json) {
localStorage.setItem("moviesData", JSON.stringify(json));
operation.success(json);
});
}
else {
if (combobox.text() == '' || combobox.text() == undefined) {
var retval = $.parseJSON(cashedData);
operation.success(retval);
} else {
$.getJSON(url, { searchvalue: combobox.text() }, function (json) {
operation.success(json);
});
}
}
}
},
schema: { data: "Table" }
}),
ShowToggleImage: false,
headerTemplate: '<div class="dropdown-header">' +
'<span class="k-widget k-header"><a onclick="addNewRecord(\'movies\')">Add New</a></span>' +
'<span class="k-widget k-header"><a onclick="clearComboVal(\'movies\')">Clear</a></span></div>',
template: '<span class="k-state-default"><h3>#: data.Display #</h3><p>#: data.Display2 #</p></span>',
});
var combobox = $("#movies").data("kendoComboBox");
combobox.input.keyup(function (event) {
if (combobox.text().length == 0) {
combobox.dataSource.read();
combobox.value('');
} else if (combobox.text().length >= 3) {
if (event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13) {
combobox.dataSource.read();
}
}
});
$(document).off('click', '#jumpMovie').on('click', '#jumpMovie', function () {
if (combobox.value() != '') {
alert(combobox.value());
}
});
function clearComboVal(ctrlname) {
var me = $('#' + ctrlname).data("kendoComboBox");
me.value('');
}
function addNewRecord(ctrlname) {
var me = $('#' + ctrlname).data("kendoComboBox");
me.dataSource.add({ CPSWGUID: "3FB46FDE-E333-424B-8690-2B4D9EC20090", Display: "Record, New" });
me.value("3FB46FDE-E333-424B-8690-2B4D9EC20090");
}
This is something I'm hoping to use as a standalone control several places in the application and would ideally also like to have it embedded in grids. My questions are:
1. Is it possible to wrap something like this in an editor in a grid so that the datasources are individual to the cells being looked at?
2. How would I refer to the data("kendoCombobox") in the datasource of the combobox in a generic way where I wouldn't have to specify the id of control itself? This would probably be necessary for anywhere that "movies" is explicitly stated.
Thanks for your help.