Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trkrameshkumar/5d3bb6f224448dee8fc6 to your computer and use it in GitHub Desktop.
Save trkrameshkumar/5d3bb6f224448dee8fc6 to your computer and use it in GitHub Desktop.
select2 ajax example with formated result
$("#selector").select2({
width: "200px",
placeholder: "Search for a item",
minimumInputLength: 3,
ajax: {
url: "/url",
dataType: "json",
data: function(term, page) {
return {
q: term,
max: 10
};
},
results: function(data) {
var myResults;
myResults = [];
$.each(data, function(index, item) {
myResults.push({
id: item.id,
text: item.email + " " + "[ " + item.name + " ]"
});
});
return {
results: myResults
};
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment