Request:
A simple textbox where users type in a certain value. based on the this value,a suggestion appears by searching the values of a specific field in a specified list.
The solution has to be easy to maintain, performance is very important (more than 100 000 items) and it has to support all the browsers that SharePoint 2010 supports.
finally, it has to be a sandbox solution.
Solution:
Used technologies:
- out-of-the-box SharePoint 2010 REST Services
- JQuery & JQuery UI
Code:
<script language="ecmascript" type="text/ecmascript">
// Settings
var url = "http://vwds242/_vti_bin/listdata.svc/Large()";
var field = "Title";
// Onload
$(document).ready(function () {
$("#tags").autocomplete({
source: function (req, add) {
var suggestions = search(req.term, url, field);
add(suggestions);
}
});
});
// Search all the listitems by using the REST Service
// Value is the text that needs to be used in the query
// listurl is the listdata.svc url withouth the filter params
// field is the name of the field where the value in exists
function search(value, listurl, field) {
var coll = new Array();
var url =
listurl + "?$filter=startswith(" + field + ",'" + value + "')";
$.ajax({
cache: true,
type: "GET",
async: false,
dataType: "json",
url: url,
success: function (data) {
var results = data.d.results;
for (att in results) {
var object = results[att];
for (attt in object) {
if (attt == field) {
coll.push(object[attt]);
}
}
}
}
});
return coll
}
</script>

Thanks for this, though I could not get it to work
Questions:
1) Does this need reference to any JQuery files? Which ones please?
2) In settings the “Large()” is the “Large” the list name? Or what is it?
Thanks a lot buddy, I hope to make it work for me.
Cheers.
This worked, thanks!!! To the above, Large() is the name of the SP List, I included the latest jquery and jquery UI plugin
Sorry I am new to JQuery, and will greatly appreciate if you could give the specific file names for what you say is “latest jquery and jquery UI plugin”.
Thanks a lot
Pingback: SharePoint @ Big Scholar » Blog Archive » SharePoint 2010 autocomplete textbox containing listitems
HI,
http://vwds242/_vti_bin/listdata.svc/Large() , here wat is listdata.svc and wat is Large()
In my site I have a list called comments, i entered my site address like this, http://abc123:1234/lists/comments
It did not work for me what to do?
Hi reenu
Large is the name of my list and listdata.svc is the SharePoint REST service.
If you want, more information is provided here:
http://msdn.microsoft.com/en-us/library/ff798339.aspx
Hi Thanks a lot TOM,
I was not aware of how to use REST, now I could able to run this in my sites home page, and I referenced both J query and UI plugins in the web part itself, however when I added this web part to another page, it doesn’t seem to be working, I am getting an error like, $(“#tags”).autocomplete is not a function. My input ID is tags itself. Can you kindly give some suggestions on this?
Hi… thanks.. it works great.
just a question..
Why Sandbox solution?