Created
September 13, 2014 09:01
-
-
Save dfch/f2d1df81136f1dff6b10 to your computer and use it in GitHub Desktop.
[NoBrainer] Using JayData with jQuery select2 plugin in LightSwitch HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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