Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[NoBrainer] Using JayData with jQuery select2 plugin in LightSwitch HTML
function searchData(svcUrl, data, searchTerm) {
var context = new LightSwitchApplication.ApplicationData({
name: 'oData',
oDataServiceHost: svcUrl
});
return context
.EntitySet
.filter(function (entity) {
return entity.Name.startsWith(this.q);
}, { q: searchTerm })
.forEach(function (entity) {
data.results.push({ id: entity.Id, text: entity.Name });
});
}
function _addSelect2Control(svcUrl, $parentElement, $element, contentItem, options) {
try {
var items = { results : [] };
$element
.select2({
placeholder: options["placeholder"],
quietMillis: options["quietMillis"],
minimumInputLength: options["minimumInputLength"],
page_limit: options["page_limit"],
width: '90%',
query: function (query) {
items.length = 0;
var promise = searchData(svcUrl, items, query.term)
.then(function () {
query.callback(items);
});
},
dropdownCssClass: options["dropdownCssClass"]
})
.on("change", function (e) {
contentItem.value = getSelectedValues($parentElement);
});
} catch (e) {
console.log(e.message + " description: " + e.description);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.