Thursday, July 14, 2011

single quotes for a string in xslt when filtering list data in sharepoint

some times, we may come accross using xslt list view webpart for showing list content and also we may need to filter data based on some query string or some other data.

That data need to be embeded in single quotes ( ' ') to pass it as filter criteria. in such case there concatination of single quote and your required string wont work.

to fulfill this requirement, create a with value = " ' " (i.e., to store single quote)and make use of this variable + ur filter string for filter criteria of that xslt list view webpart.


i am sorry, i couldnt give u sample code. will update this post with sample code soon.

thank u
Raj

Client Object Model to fetch data from sharepoint list

Below ExecuteOrDelay...line should be first line before you execute any client object model script

ExecuteOrDelayUntilScriptLoaded(funDefault, "sp.js");

var context = null; 
var web = null; 

context = new SP.ClientContext.get_current(); 
web = context.get_web(); 
context.load(web);
var list = web.get_lists().getByTitle("Employees"); 
var camlQuery = new SP.CamlQuery(); 
var q = ""++"100"; 
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery); 

context.load(listItems,'Include(DisplayName,Id,EmpFullName)'); //what ever field you want from Employee list, you can specify here. DisplayName is nothing but 'Title'

context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod)); 


function onSuccessMethod(sender, args) 
{
var listEnumerator = this.listItems.getEnumerator(); 
if(this.listItems.get_count()!=0) 
{
while (listEnumerator.moveNext()) 
{
var item = listEnumerator.get_current(); 
var title = item.get_displayName(); 
var body=new Option(title, item.get_item('Body')); 
document.getElementById('divMain').innerHTML=item.get_item('EmpFullName'); //divMain is a div that i added in content editor webpart
}
}



 
function onFailureMethod(sender, args) 
{
alert('request failed....' + args.get_message() + '\n' + args.get_stackTrace()); 
}