Category Archives: List view modification

Inline editing for SharePoint 2007

25.08.2012 v3.0 Fixed a bug where you could not have multiple views of the same list in a page. This update lets you have multiple lists / views of the same list in a page, and have the inline editing feature activated on all of them. The argObj property “myListGuid” is now obsolete. You must use jQuery v1.6 or above. Please note that there are an issue with the frozen header in IE when using jQuery 1.8.


31.05.2012 v2.8 BETA: Added support for single and multi lookup columns.


25.05.2012 v2.7: Added support for frozen list view header in Chrome and Firefox in addition to the existing IE support.


17.05.2012 v2.6.3: Fixing positioning error in IE when scrolling and added a method of clearing a datepicker value by hitting the Delete key when the datepicker is active.


19.02.2012 v2.6 fixed a bug when trying to save “<“, “>” or “&” in a text field. Changed the script to use spjs-utility.js. Note that this version requires jQuery v1.6.4 or newer.


19.02.2012 v2.5 fixes bugs with “pinTableHeader” and grouped views.


28.09.2011 v2.4 fixes a bug preventing this to work with folders.


11.08.2011 v2.3 fixed a bug (from v2.2) that made it impossible to use the solution in document libraries. I have also changed the variables passed to the function “initCustomEditFunction” to an object literal. See updated CEWP below.


08.05.2011 v2.2 makes it possible to use this solution in a web part page alongside other list view web parts.

NOTE:
You can have only one list view web part with this feature activated in one web part page.

Both the CEWP code and the file “inlineEditingForSP2007.js” has changed.


09.02.2011 v2.1 released with this modifications:
Modified the “hover” CSS to highlight the editable TD’s only, and to show a small downarrow in the bottom right corner of the TD.


I have previously created a solution for editing items inline in a list view. You find it here This solution did not support choice fields or multi line text fields.

I stated a long time ago that i would update the solution to support choice fields, but never had the time to implement it. This added feature was requested a few weeks ago, and i had to deliver…

I will put this in a new post as it is completely rewritten.


This solution features inline editing of the following field types in plain list views and in grouped views:

  • Date and Time
  • Single line of text
  • Number
  • Currency
  • Yes/No
  • Person or Group (Single choice)
  • Dropdown choice
  • Radio buttons
  • Checkboxes
  • Multiple lines of text (Plain text)

Hover:
IMG
Edit:
IMG
In Internet Explorer the list view heading row will scroll with the page. This feature is supported in IE only as you cannot have a <tr> with css position:relative in any other browser, and i haven’t had the time to find a workaround.

The code is tested in IE8, Firefox 3.6.13, Chrome 9.0.597.84 and in Safari 5.0.2

It runs much faster than the previous solution – even in large list views. This is due to the method it is created – addressing the <tr> and not each <td> in the first pass. The <td>’s are processed on hover over the <tr>.

You must have the ID column in the view for this solution to work. If you use the option to hide the ID column, it has to be positioned to the far right in th view.

The fields are edited “one at the time” and you must save changes for each individual field.

This solution relies upon “Google Libraries API” to host the jQuery and the jQueryUI. If you prefer local copies, edit the script src in the CEWP code.

Download the code

Get the latest version of the file “InlineEditingForSP2007.js” from here

Put this in a document library or a folder made in SharePoint Designer. Make sure all users have read access to the location. When inserting the CEWP code below, make sure to update the src to reflect your locale copy of the file “InlineEditingForSP2007.js”.

Add this code to a CEWP below the list view

For v2.0-2.2

&lt;link type=&quot;text/css&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/EditInListView/inlineEditingForSP2007.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Set variables
	var dateFormat = 'm/d/yy';
	var boolYesNoText = 'Yes|No';
	var arrToEdit = [];

// If there are only one list view web part in the page, we can rely upon SharePoint to provide the list GUID:
	myListGuid = ctx.listName;

// To use the solution in a web part page with more than one list view web part you must provide the list GUID manually:
	//var myListGuid = &quot;{B9F1D8CF-83DB-4E1A-BF61-752BCB40B2CF}&quot;; // Change this GUID to match your's

// This parameter specifies whether to pin the table header to the top of the screen when scrolling (IE only)
	var pinTableHeader = true;

// The symbol used to mark the boundary between the integral and the fractional parts of a decimal number
	var decimalSeparator = '.'; 

// Hide the ID column
	var hideIdColumn = true;	
// Call function
	initCustomEditFunction(hideIdColumn);
&lt;/script&gt;

For v2.3+

&lt;link type=&quot;text/css&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/EditInListView/inlineEditingForSP2007.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/spjs-utility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

var argObj = {dateFormat:'m/d/yy',
			  decimalSeparator:'.',
			  boolYesNoText:'Yes|No',
			  labelArr:['Save','Cancel','Clear'],
			  arrToEdit:[],
			  myListGuid:'B9F1D8CF-83DB-4E1A-BF61-752BCB40B2CF',
			  pinTableHeader:true,
			  hideIdColumn:true};
	initCustomEditFunction(argObj);	
&lt;/script&gt;

For v3.0+

&lt;link type=&quot;text/css&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/redmond/jquery-ui.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/EditInListView/inlineEditingForSP2007.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/spjs-utility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

var argObj = {dateFormat:'m/d/yy',
			  decimalSeparator:'.',
			  boolYesNoText:'Yes|No',
			  labelArr:['Save','Cancel','Clear'],
			  arrToEdit:[],
			  pinTableHeader:true,
			  hideIdColumn:true};
	initCustomEditFunction(argObj);	
&lt;/script&gt;

New in v2.6
I have removed some functions from the file “inlineEditingForSP2007.js” and you must refer spjs-utility.js in the CEWP

New in v3.0
The argObj property “myListGuid” is now obsolete.

Parameters explained:

  • dateFormat: This must reflect the current regional settings for the picker to “pick up” the date in the field and display it correctly in the datepicker.
  • boolYesNoText: Used to display Yes or No in the field when it is changed. Only cosmetics as the “real” value is 0 or 1.
  • labelArr: The text on the links when in edit mode on a field. New in v2.3
  • arrToEdit: Optional. To restrict edit to a selection of fields, enter them here by FieldInternalName in an array format. Defaults to All editable fields in the current view.
  • myListGuid Obsolete in v3.0: If there are only one list view web part in the page, we can rely upon SharePoint to provide the list GUID using
    myListGuid = ctx.listName
  • myListGuid Obsolete in v3.0: To use the solution in a web part page with more than one list view web part you must provide the list GUID manually
    myListGuid = PutTheListGuidHere
  • pinTableHeader: This parameter specifies whether to pin the table header to the top of the screen when scrolling (IE only)
  • decimalSeparator: The symbol used to mark the boundary between the integral and the fractional parts of a decimal number
  • hideIdColumn: The argument passed in the function call – true to hide the ID column, false to keep it visible.

Read here how to find the list GUID

Please ask if anything is unclear.

Alexander

List all attachments when clicking the paperclip in a list view

Change log:

07.10.2011 A new version is published – you find it here.

23.09.2010 Moved the code to a server for direct download to make it easier for the users. You find the link below. The current stable version is 1.5.

13.09.2010 Fixed bug when ID column was not placed to the far right.

07.09.2010 Fixed bug when list view was not the topmost webpart.

30.08.2010 Added “one click open” if only one attachment is found.


I got this request from Chris:

…the challenge I’m currently trying to solve is to get the attachments paperclip in a listview clickable. Using a doclib and linking against the file is not an option since we are talking about a lot of files with the same name which should be stored with the list entry (one file per entry).

There’s a solution from Paul Grenier at EUSP, but that doesn’t work for large collections, so it’s not usable.

I thought of setting up the path ‘manually’, and displaying this entry, since I noticed that the attachment path is always like URL/site/lists/listname/attachments/list_item_id/filename. Though I might be able to come up with all the details up to the ID I have no idea on how to get the filename automatically.

Can you think of any other way to make the paperclip clickable to open the attachment?

Thanks,
Chris


Here we go:

This method uses the webservice lists.asmx and the operation GetAttachmentCollection.

It is tested in IE8, Chrome 5.0 and Firefox 3.6.8 in WSS3.0. It works in both standard list views, and grouped views.

It has briefly been tested in SP2010, but is only partially compatible (minor issue with the click on the paperclip selecting the row, and it only works in non-grouped views).

The only requirement for this solution to work is the ID column being in the view – it can be hidden by setting the variable hideIdColumn = true (default).

The CEWP code

&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/test/English/Javascript/previewAttachmentsOnClick.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

   hideIdColumn = true;
   customListAttachments();

&lt;/script&gt;

Place the CEWP below the list view!

Download the file “previewAttachmentsOnClick.js” from this location

Note:

When new versions are released, they will be placed in a folder with the version number as label. Be sure to download the latest version.

If you are using a browser other than IE, right click the file and select “Save link as” or “Save linked content as…”.

As if anything is unclear.

Alexander

Visual status indicator based on 5 date columns in a list view

31.07.2010 Updated the code for the file “FiveDateColumnStatus.js” and the CEWP code for ListView, NewForm, DispForm and EditForm. Added support for column name in the mouse over tooltip and the percentage is now “0 %” if none of the date fields are applicable. The CEWP code has changed as the “arrOfFields” has become an object (changed the parameter name to “arrOfFieldsObj”).

29.07.2010 Fixed bug when using using calculated columns and a date field is empty. Thanks to Charlie Epes for noticing the bug. The code for the file “FiveDateColumnStatus.js” is updated.

16.07.2010 Updated the file “FiveDateColumnStatus.js” to support calculated columns.

03.07.2010 Updated the code to add DispForm integration and made the number of “date fields” dynamic – you can add as many as you like to the array. The code in the file “FiveDateColumnStatus.js” is updated, and there has been added a new section for DispForm.

I got an e-mail from Charlie Epes about a ticket over at STP

Hi Alexander:
You are mentioned in the thick of a request started by me. If you want to chime in here, please do!

http://www.endusersharepoint.com/STP/viewtopic.php?f=10&t=1319

My challenge was:
Here’s an example of what I’m trying to do in my List.

Let’s say my dog’s veterinarian offers 5 shots for my dog. The vet’s record needs to show the expiration of each of the 5 shots. The vet likes to keep a “score” for my dog showing that Rover is 80% up to date on his shots.

Of course there are exceptions. My dog will never need 1 of the shots, so it’s “not applicable” and using it as one of the 5 to calculate my percentage throws off my score. I figure that entering a distant date of 12/31/8900 would indicate that the shot is not applicable.

In my case, I’m using a List to indicate the “Health” of a client’s files by giving each client an overall score based on how up to date “eligible” files are.


I do not mean to hijack this discussion, but this code was to complex to insert in a comment over at STP… Feel free to continue the discussion where it originally started.

I thought of it and found that i could do this in another way than Charlie and Dessie had going in the discussion.

My approach reuses some scripts from this article Vertical Scrolling WebPart to get the items from a list view.

It then parses the dates and present the status by colored “boxes” and a “percent complete” value like this:
IMG

IMG

IMG = a date to come
IMG = a date that has passed
IMG = a date that is applicable, but is empty
IMG = a date that does not apply

It provides a mouse over with the “Overdue by X days” or “Due in X days”

This approach can be used with grouped views.

I have separated the main code in a file named “FiveDateColumnStatus.js”. This file should be saved locally and refered in the CEWP code. The code is found below.

To use this solution you have to:
Create some date columns, corresponding Yes/No type columns and one calculated column with the formula =”*Status*”

The date columns does not have to be in the list view, but the calculated column to hold the status and the “Title (linked to item with edit menu)” must be.

A modification from Charlie’s original idea is the presence of a checkbox for each date field to indicate whether it is applicable and should count in the total percentage – or not.
IMG
If the Checkbox is not checked – the corresponding date column is hidden.

NewForm and EditForm


This code goes in a CEWP below NewForm and/or EditForm and hides the date fields if the corresponding Yes/No column is not checked:

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
fields = init_fields_v2();
/*
 This code goes in a CEWP below NewForm and/or EditForm and hides the date fields if the corresponding Yes/No column is not checked.
 arrOfDateFieldsObj: 
  Array of objects containing FieldInternalName for the date column and FieldInternalName for the bool column to select whether the date column is applicable.
  Format is {dateFIN:'FieldInternalNameOfDateColumn',applicableFIN:'FieldInternalNameOfTriggerYesNoColumn'}.
*/

var arrOfDateFieldsObj = [{dateFIN:'DateField1',applicableFIN:'Date1Applicable'},
						{dateFIN:'DateField2',applicableFIN:'Date2Applicable'},
						{dateFIN:'DateField3',applicableFIN:'Date3Applicable'},
						{dateFIN:'DateField4',applicableFIN:'Date4Applicable'},
						{dateFIN:'DateField5',applicableFIN:'Date5Applicable'}]


hideDateFieldsNotApplicable(arrOfDateFieldsObj);

function hideDateFieldsNotApplicable(arrOfFieldsObj){
	$.each(arrOfFieldsObj,function(i,obj){
		var thisChck = $(fields[obj.applicableFIN]).find(':checkbox');
		var checked = thisChck.attr('checked');
		// Onload
			if(!checked){
				$(fields[obj.dateFIN]).hide();
			}
		// Onclick
		thisChck.click(function(){
			var checked = $(this).attr('checked');
			if(checked){
				$(fields[obj.dateFIN]).show();
			}else if(!checked){
				$(fields[obj.dateFIN]).hide();
			}
		});	
	});
}

function init_fields_v2(){
	var res = {};
	$(&quot;td.ms-formbody&quot;).each(function(){
	var myMatch = $(this).html().match(/FieldName=&quot;(.+)&quot;s+FieldInternalName=&quot;(.+)&quot;s+FieldType=&quot;(.+)&quot;s+/);	
		if(myMatch!=null){
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var type = myMatch[3];
			if(type=='SPFieldNote'){
				if($(this).find('script').length&gt;0){
					type=type+&quot;_HTML&quot;;
				}
			}
			if(type=='SPFieldLookup'){
				if($(this).find('input').length&gt;0){
					type=type+&quot;_Input&quot;;
				}
			}
			// Build object
			res[fin] = this.parentNode;
			res[fin].FieldDispName = disp;
			res[fin].FieldType = type;
		}		
	});
	return res;
}
&lt;/script&gt;

DispForm


This code goes in a CEWP below the DispForm:

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/FiveDateColumnStatus.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
fields = init_fields_v2();
/* 
This code goes in a CEWP below DispForm. It displays the status field in the same way as in the list view. 
It also hides the date fields if the corresponding Yes/No column is not checked.

Parameters:
 listGuid: The GUID of this list
 arrOfDateFieldsObj: Array of objects containing FieldInternalName for the date column, DisplayName for the date column and FieldInternalName for the bool column to select whether the date column is applicable.
 Format is {dateFIN:'FieldInternalNameOfDateColumn',dateDispName:'DisplayNameOfDateColumn',applicableFIN:'FieldInternalNameOfTriggerYesNoColumn'}.
*/
var listGuid = &quot;31FFC357-74DA-4830-8288-D8214781556D&quot;;
var arrOfDateFieldsObj = [{dateFIN:'_Date1',dateDispName:'Datefield number 1',applicableFIN:'Date1Applicable'},
						{dateFIN:'DateField2',dateDispName:'Datefield number 2',applicableFIN:'Date2Applicable'},
						{dateFIN:'DateField3',dateDispName:'Datefield number 3',applicableFIN:'Date3Applicable'},
						{dateFIN:'DateField4',dateDispName:'Datefield number 4',applicableFIN:'Date4Applicable'},
						{dateFIN:'DateField5',dateDispName:'Datefield number 5',applicableFIN:'Date5Applicable'}]


// Get ID from querystring
var thisItemID = getQueryParameters().ID;
// Call function to generate &quot;Status field contents&quot;
var res = getDateFieldStatus(arrOfDateFieldsObj,{'listName':listGuid,'ID':thisItemID});
// Write back the result to the calculated field containig the value &quot;*Status*&quot;
$.each(fields,function(id,obj){
	if($(obj).find('.ms-formbody').text().match(/*Status*/)){
		$(obj).find('.ms-formbody').html(res[thisItemID].html)
	}	
});

// Hide fields that does not apply
$.each(arrOfDateFieldsObj,function(i,obj){
	var applicable = res[thisItemID][obj.applicableFIN];
	if(!applicable){
		$(fields[obj.dateFIN]).hide();
		$(fields[obj.applicableFIN]).hide();
	}
});
&lt;/script&gt;

List view


This code is used in the list view, and must be inserted in a CEWP below the list view webpart:

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/FiveDateColumnStatus.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
/* 
 arrOfDateFieldsObj:
 Array of objects containing FieldInternalName for the date column, DisplayName for the date column and FieldInternalName for the bool column to select whether the date column is applicable
 Format is {dateFIN:'FieldInternalNameOfDateColumn',dateDispName:'DisplayNameOfDateColumn',applicableFIN:'FieldInternalNameOfTriggerYesNoColumn'}
*/

var arrOfDateFieldsObj = [{dateFIN:'_Date1',dateDispName:'Datefield number 1',applicableFIN:'Date1Applicable'},
						{dateFIN:'DateField2',dateDispName:'Datefield number 2',applicableFIN:'Date2Applicable'},
						{dateFIN:'DateField3',dateDispName:'Datefield number 3',applicableFIN:'Date3Applicable'},
						{dateFIN:'DateField4',dateDispName:'Datefield number 4',applicableFIN:'Date4Applicable'},
						{dateFIN:'DateField5',dateDispName:'Datefield number 5',applicableFIN:'Date5Applicable'}]

getDateFieldStatus(arrOfDateFieldsObj);
&lt;/script&gt;

FiveDateColumnStatus.js


This is the code for the file “FiveDateColumnStatus.js”:

/* ---------------------------------------------
 * Created by Alexander Bautz
 * alexander.bautz@gmail.com
 * https://spjsblog.com
 * Copyright (c) 2010 Alexander Bautz (Licensed under the MIT X11 License)
 * v1.1
 * LastMod: 31.07.2010
 * LastChange:
 	- Variable number of date columns
 	- DispForm integration
 	- Support for calculated columns
 	- 29.07.2010: Fixed bug when using using calculated columns and a date field is empty.
 	- 31.07.2010: Added the column name in the mouseover tooltip. If none of the date fields are applicable, the percentage reads &quot;0 %&quot;.

 * See this blog post for instructions:
	
Visual status indicator based on 5 date columns in a list view
* --------------------------------------------- */ function getDateFieldStatus(arrOfFieldsObj,qParam){ if(typeof(arrOfFieldsObj)!='undefined'){ viewFieldsArr = []; dateFieldsArr = []; dateFieldsDispNameArr = []; dateApplicableArr = []; $.each(arrOfFieldsObj,function(i,obj){ dateFieldsArr.push(obj.dateFIN); dateFieldsDispNameArr.push(obj.dateDispName); dateApplicableArr.push(obj.applicableFIN); }); viewFields = viewFieldsArr.concat(['ID'],dateFieldsArr,dateApplicableArr); } if(typeof(myCustomQueryRes)=='undefined'){ wsBaseUrl = L_Menu_BaseUrl + '/_vti_bin/'; if(qParam==undefined){ myCustomQueryRes = queryItemsByViewName(ctx.listName,ctx.view,viewFields); }else{ var query = '&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ID&quot; /&gt;&lt;Value Type=&quot;Text&quot;&gt;' + qParam.ID + '&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;'; myCustomQueryRes = queryItemsByCAML(qParam.listName,query,viewFields); } if(myCustomQueryRes.count==-1){ alert(&quot;An error occured in the query.&quot;); }else{ resObj = {}; var now = new Date(); $.each(myCustomQueryRes.items,function(i,item){ var thisID = item.ID; resObj[thisID] = {}; var dArr = []; $.each(dateFieldsArr,function(j,fin){ if(item[dateApplicableArr[j]]==1){ dArr.push((item[fin]==null)?'':item[fin].replace(/w+;#/,'').split('-')); // Add to the object: applicable resObj[thisID][dateApplicableArr[j]]=true; }else{ dArr.push('NotApplicable'); // Add to the object: not applicable resObj[thisID][dateApplicableArr[j]]=false } }); var percent = 0; var increment = ((100/dArr.length)*100)/100; var htmlBuffer = []; var notApplicableCount = 0; $.each(dArr,function(idx,dateArr){ if(typeof(dateArr)=='object'){ if(dateArr.length==1){ date = ''; }else{ var y = dateArr[0]; var m = (dateArr[1]-1); var d = dateArr[2].substring(0,dateArr[2].indexOf(' ')); var date = new Date(y,m,d); } }else if(dateArr=='NotApplicable'){ notApplicableCount += 1; date = 'NotApplicable'; }else if(dateArr==undefined){ date = ''; } var dummyIMG = &quot;&lt;img src='&quot;+L_Menu_BaseUrl+&quot;/_layouts/images/blank.gif' style='height:7px;width:7px;border:1px silver solid'&gt;&quot;; if(date==''){ htmlBuffer.push(&quot;&lt;span title='&quot;+dateFieldsDispNameArr[idx]+&quot; is empty' style='background-color:yellow'&gt;&quot;+dummyIMG+&quot;&lt;/span&gt;&quot;); }else if(date=='NotApplicable'){ percent+=increment; htmlBuffer.push(&quot;&lt;span title='&quot;+dateFieldsDispNameArr[idx]+&quot; is not applicable' style='background-color:white'&gt;&quot;+dummyIMG+&quot;&lt;/span&gt;&quot;); }else if(date&gt;now){ percent+=increment; var countDays = Math.floor(((date-now)/86400000)*10)/10; // 86400000 in one day var postfix = (countDays&gt;1)?&quot;s&quot;:''; htmlBuffer.push(&quot;&lt;span title='&quot;+dateFieldsDispNameArr[idx]+&quot; is due in &quot;+countDays+&quot; day&quot;+postfix+&quot;' style='background-color:green'&gt;&quot;+dummyIMG+&quot;&lt;/span&gt;&quot;); }else{ var countDays = Math.floor(((now-date)/86400000)*10)/10; // 86400000 in one day var postfix = (countDays&gt;1)?&quot;s&quot;:''; htmlBuffer.push(&quot;&lt;span title='&quot;+dateFieldsDispNameArr[idx]+&quot; is overdue by &quot;+countDays+&quot; day&quot;+postfix+&quot;' style='background-color:red'&gt;&quot;+dummyIMG+&quot;&lt;/span&gt;&quot;); } }); if(notApplicableCount==dArr.length){ var percentagePostfix = &quot;0 %&quot;; }else{ var percentagePostfix = Math.floor(percent)+&quot; %&quot;; } resObj[thisID].html=htmlBuffer.join('&amp;nbsp;')+&quot; &quot;+percentagePostfix; }); } } if(qParam==undefined){ updateView(resObj); }else{ return resObj; } } function updateView(obj){ $(&quot;table.ms-listviewtable td:contains('*Status*')&quot;).each(function(){ var lineID = $(this).parent().find('table.ms-unselectedtitle').attr('id'); $(this).html(obj[lineID].html); }); } // Attaches a call to the function to the &quot;expand grouped elements function&quot; for it to function in grouped listview's function ExpGroupRenderData(htmlToRender, groupName, isLoaded){ var tbody=document.getElementById(&quot;tbod&quot;+groupName+&quot;_&quot;); var wrapDiv=document.createElement(&quot;DIV&quot;); wrapDiv.innerHTML=&quot;&lt;TABLE&gt;&lt;TBODY id=&quot;tbod&quot;+groupName+&quot;_&quot; isLoaded=&quot;&quot;+isLoaded+&quot;&quot;&gt;&quot;+htmlToRender+&quot;&lt;/TBODY&gt;&lt;/TABLE&gt;&quot;; tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody); getDateFieldStatus(); } /***************************************************** Web service calls *****************************************************/ function queryItemsByCAML(listName, query, viewFields, rowLimit, pagingInfo){ var content = wrapQueryContent({'listName':listName,'query':query,'rowLimit':rowLimit,'viewFields':viewFields,'pagingInfo':pagingInfo}); var result = {count:-1, nextPagingInfo:'', items:[]}; wrapSoapRequest(wsBaseUrl + 'lists.asmx', 'http://schemas.microsoft.com/sharepoint/soap/GetListItems', content, function(data){ result.count = $(data).find(&quot;[nodeName='rs:data']&quot;).attr('ItemCount'); result.nextPagingInfo = $(data).find(&quot;[nodeName='rs:data']&quot;).attr('ListItemCollectionPositionNext'); $(data).find(&quot;[nodeName='z:row']&quot;).each(function(idx, itemData){ var fieldValObj = {} $.each(viewFields,function(i,field){ var value = $(itemData).attr('ows_' + field); if(value == undefined) value = null; fieldValObj[field]=value; }); result.items.push(fieldValObj); }); }); return result; } // Function to pull items from view function queryItemsByViewName(listName, viewName, viewFields, pagingInfo){ var content = wrapQueryContent({'listName':listName,'viewName':viewName,'viewFields':viewFields,'pagingInfo':pagingInfo}); var result = {count:-1, nextPagingInfo:'', items:[]}; wrapSoapRequest(wsBaseUrl + 'lists.asmx', 'http://schemas.microsoft.com/sharepoint/soap/GetListItems', content, function(data){ result.count = $(data).find(&quot;[nodeName='rs:data']&quot;).attr('ItemCount'); result.nextPagingInfo = $(data).find(&quot;[nodeName='rs:data']&quot;).attr('ListItemCollectionPositionNext'); $(data).find(&quot;[nodeName='z:row']&quot;).each(function(idx, itemData){ var fieldValObj = {} $.each(viewFields,function(i,field){ var value = $(itemData).attr('ows_' + field); if(value == undefined) value = null; fieldValObj[field]=value; }); result.items.push(fieldValObj); }); }); return result; } function wrapQueryContent(paramObj){ var result = []; result.push('&lt;GetListItems xmlns=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;&gt;'); result.push('&lt;listName&gt;' + paramObj.listName + '&lt;/listName&gt;'); if(paramObj.viewName!=undefined){ result.push('&lt;viewName&gt;' + paramObj.viewName + '&lt;/viewName&gt;'); } if(paramObj.query != null &amp;&amp; paramObj.query != ''){ result.push('&lt;query&gt;&lt;Query xmlns=&quot;&quot;&gt;'); result.push(paramObj.query); result.push('&lt;/Query&gt;&lt;/query&gt;'); } if(paramObj.viewFields != null &amp;&amp; paramObj.viewFields.length &gt; 0){ result.push('&lt;viewFields&gt;&lt;ViewFields xmlns=&quot;&quot;&gt;'); $.each(paramObj.viewFields, function(idx, field){ result.push('&lt;FieldRef Name=&quot;' + field + '&quot;/&gt;'); }); result.push('&lt;/ViewFields&gt;&lt;/viewFields&gt;'); } if(paramObj.rowLimit != undefined &amp;&amp; paramObj.rowLimit != null &amp;&amp; paramObj.rowLimit &gt; 0){ result.push('&lt;rowLimit&gt;' + paramObj.rowLimit + '&lt;/rowLimit&gt;'); }else{ result.push('&lt;rowLimit&gt;100000&lt;/rowLimit&gt;'); } result.push('&lt;queryOptions&gt;&lt;QueryOptions xmlns=&quot;&quot;&gt;&lt;IncludeMandatoryColumns&gt;FALSE&lt;/IncludeMandatoryColumns&gt;'); if(paramObj.pagingInfo != undefined &amp;&amp; paramObj.pagingInfo != null &amp;&amp; paramObj.pagingInfo != '') result.push('&lt;Paging ListItemCollectionPositionNext=&quot;' + paramObj.pagingInfo.replace(/&amp;/g, '&amp;amp;') + '&quot; /&gt;'); result.push('&lt;/QueryOptions&gt;&lt;/queryOptions&gt;'); result.push('&lt;/GetListItems&gt;'); return result.join(''); } function wrapSoapRequest(webserviceUrl,requestHeader,soapBody,successFunc){ var xmlWrap = []; xmlWrap.push(&quot;&lt;?xml version='1.0' encoding='utf-8'?&gt;&quot;); xmlWrap.push(&quot;&lt;soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;&quot;); xmlWrap.push(&quot;&lt;soap:Body&gt;&quot;); xmlWrap.push(soapBody); xmlWrap.push(&quot;&lt;/soap:Body&gt;&quot;); xmlWrap.push(&quot;&lt;/soap:Envelope&gt;&quot;); xmlWrap = xmlWrap.join(''); $.ajax({ async:false, type:&quot;POST&quot;, url:webserviceUrl, contentType:&quot;text/xml; charset=utf-8&quot;, processData:false, data:xmlWrap, dataType:&quot;xml&quot;, beforeSend:function(xhr){ xhr.setRequestHeader('SOAPAction',requestHeader); }, success:successFunc }); } /********************************* Helper functions *********************************/ // Function to separate each url search string parameters function getQueryParameters(){ qObj = {}; var urlSearch = window.location.search; if(urlSearch.length&gt;0){ var qpart = urlSearch.substring(1).split('&amp;'); $.each(qpart,function(i,item){ var splitAgain = item.split('='); qObj[splitAgain[0]] = splitAgain[1]; }); } return qObj; } function init_fields_v2(){ var res = {}; $(&quot;td.ms-formbody&quot;).each(function(){ var myMatch = $(this).html().match(/FieldName=&quot;(.+)&quot;s+FieldInternalName=&quot;(.+)&quot;s+FieldType=&quot;(.+)&quot;s+/); if(myMatch!=null){ // Display name var disp = myMatch[1]; // FieldInternalName var fin = myMatch[2]; // FieldType var type = myMatch[3]; if(type=='SPFieldNote'){ if($(this).find('script').length&gt;0){ type=type+&quot;_HTML&quot;; } } if(type=='SPFieldLookup'){ if($(this).find('input').length&gt;0){ type=type+&quot;_Input&quot;; } } // Build object res[fin] = this.parentNode; res[fin].FieldDispName = disp; res[fin].FieldType = type; } }); return res; }

Save as “FiveDateColumnStatus.js” – mind the file extension and update the script “src” in the CEWP code to point to where you save this script.

Ask if anything is unclear!
Alexander

Show field description in list view column header

15.05.2012 You find an updated version here.
08.07.2010 Updated the code to make it cross compatible for SP2007 and SP2010.


I got this request from Saran to display the field description when hovering the mouse over the column header in a list view.

IMG

Add this code to a CEWP and place it below the list view:

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

if(typeof(_fV4UI)==='undefined'){ // SP2007
	var myTooltipObj = customGetList(ctx.listName);	
	$(&quot;.ms-listviewtable th&quot;).each(function(){
		var fieldDisplayName = $(this).find(&quot;table:first&quot;).attr('DisplayName');	
		if(fieldDisplayName==undefined){
			fieldDisplayName = $(this).text();
		}
		if(myTooltipObj[fieldDisplayName]!=undefined){
			$(this).attr('title',myTooltipObj[fieldDisplayName]).find('a').attr('title',myTooltipObj[fieldDisplayName]);;
		}
	});
}else{ // SP2010
	var myTooltipObj = customGetList(_spPageContextInfo.pageListId);	
	$(&quot;div.ms-vh-div&quot;).each(function(){
		var fieldDisplayName = $(this).attr('DisplayName');
		if(myTooltipObj[fieldDisplayName]!==undefined){
			$(this).attr('title',myTooltipObj[fieldDisplayName]);
		}
	});
}

function customGetList(listName){
	xmlStr = [];
	xmlStr.push('&lt;GetList xmlns=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;&gt;');
	xmlStr.push('&lt;listName&gt;' + listName + '&lt;/listName&gt;');
	xmlStr.push('&lt;/GetList&gt;');
	xmlStr = xmlStr.join('');
	var result = {};
	wrapSoapRequest(L_Menu_BaseUrl + '/_vti_bin/lists.asmx', 'http://schemas.microsoft.com/sharepoint/soap/GetList', xmlStr, function(data){
		$('Field', data).each(function(i){
			if(result[$(this).attr('DisplayName')]==undefined || result[$(this).attr('DisplayName')]==''){
				result[$(this).attr('DisplayName')] = ($(this).attr('Description')==undefined)?'':$(this).attr('Description');
			}
		});
	});
	return result;
}

function wrapSoapRequest(webserviceUrl,requestHeader,soapBody,successFunc){
	var xmlWrap = [];
		xmlWrap.push(&quot;&lt;?xml version='1.0' encoding='utf-8'?&gt;&quot;);
		xmlWrap.push(&quot;&lt;soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;&quot;);
		xmlWrap.push(&quot;&lt;soap:Body&gt;&quot;);
		xmlWrap.push(soapBody);
		xmlWrap.push(&quot;&lt;/soap:Body&gt;&quot;);
		xmlWrap.push(&quot;&lt;/soap:Envelope&gt;&quot;);
		xmlWrap = xmlWrap.join('');
	$.ajax({
		async:false,
		type:&quot;POST&quot;,
		url:webserviceUrl,
		contentType:&quot;text/xml; charset=utf-8&quot;,
		processData:false,
		data:xmlWrap,
		dataType:&quot;xml&quot;,
		beforeSend:function(xhr){
			xhr.setRequestHeader('SOAPAction',requestHeader);
		},
		success:successFunc
	});
}
&lt;/script&gt;

Note: This will only work when only one list view webpart is in the page.

Ask if anything is unclear.

Alexander

Image preview on hover over a hyperlink field

05.05.2010 Updated code to adapt the position of the image depending on height and width (and scroll) of the page relative to the image size.


I got this request from Mark:

Hi Alexander,

I did not include the column as a picture because they are to big to display in the list view. For this reason I setup a list with a hyperlink to the image.

Besides it would look terrible having a list that displays all these large pictures in a list view. For that reason, I have been trying to find some way to display an image from a list when a user hovers over a row or column.


IMG
Add this code to a CEWP below the list view, and it will add a hover function to all hyperlinks including an image (add more types to the array “arrOfImageTypes”):

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

function imagePreview(){
arrOfImageTypes = ['jpg','jpeg','gif','png'];
	$(&quot;table.ms-listviewtable td.ms-vb2 a&quot;).hover(function(e){
		var href = this.href;
		var img = href.substring(href.lastIndexOf('.')+1).toLowerCase();
		if(href.indexOf('http')==0 &amp;&amp; $.inArray(img,arrOfImageTypes)&gt;-1){
		    $(&quot;body&quot;).append(&quot;&lt;img id='preview' src='&quot;+ this.href +&quot;' alt='Image preview' /&gt;&quot;);	
		}
		var obj = $(&quot;#preview&quot;);		
		var offset = $(this).offset();
		var winHeight = $(window).height();
		var winWidth = $(window).width();
		var scrollLeft = $(window).scrollLeft();
		var scrollTop = $(window).scrollTop();
		var objHeight = obj.outerHeight();
		var objWidth = obj.width()+15;
		if(((winWidth+scrollLeft)-offset.left)&lt;objWidth){
			offset.left=((winWidth+scrollLeft)-objWidth);
		}
		var maxHeight = (winHeight+scrollTop)-offset.top;
		if(objHeight&gt;maxHeight){
			if(offset.top-scrollTop&gt;objHeight){
				offset.top=offset.top-objHeight-20;
			}
			height = (objHeight&lt;winHeight)?objHeight:winHeight;
		}							 
		obj.css({&quot;position&quot;:&quot;absolute&quot;,&quot;top&quot;:(offset.top+20)+&quot;px&quot;,&quot;left&quot;:offset.left+20})
		.fadeIn(&quot;fast&quot;);						
	},
	function(){
		$(&quot;#preview&quot;).remove();
	});			
};

// Call the script on page load
$(document).ready(function(){
	imagePreview();
});
&lt;/script&gt;

Regards
Alexander

Toggle column visibility in list view

25.08.2011 I have ported this to SharePoint 2010. The instruction for use is the same as for v1.4 for SharePoint 2007. You find the code in the download section.


24.08.2011 I have released a new version (v1.4) that adds the following new feature requested by Bill G:
Added a new parameter “arrDoNotRender”. This is an array of fields passed as an argument to the function “init_Checkboxes”.
The fields in this array will not render as a checkbox, but can be prehidden using the array “arrOfPreHiddenColumns” or passed as an argument in the URL.

There are changes to:
The file “ToggleColumnVisibility.js” and the CEWP-code.


Change log:

30.08.2010 Added the ability to skip one or more columns by adding them to the array “arrOfFieldInternalNamesToSkip”. Both the CEWP code and the file “ToggleColumnVisibility.js” has changed.

19.05.2010 Modified code to support multiple list views in the same page. The code is not fully tested so please report any bugs. Only the code for the file ToggleColumnVisibility.js” has changed.

19.04.2010 Modified code to support “pre hiding” from query string parameter. Both the CEWP code and the file “ToggleColumnVisibility.js” has changed.


Here are a solution for toggling the columns visibility in a list view by adding a checkbox row above the list view. Remove the check to hide the column. recheck to show.

The solution dynamically adapts to the columns in the view.
IMG

IMG

As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
IMG

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.4.2.min. If you download another version, please update the code in the CEWP.

The sourcecode for the file “ToggleColumnVisibility.js” is provided below.

Add this code to a CEWP below the list view:
For v1.3

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/ToggleColumnVisibility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// To &quot;pre uncheck&quot; checkboxes, add names to this array
	var arrOfPreHiddenColumns = ['MyPeoplePicker','My multi line'];
// Pull columns to &quot;pre uncheck&quot; from the query string parameter &quot;ColumnsToHide&quot;
	var qStrPAram = getQueryParameters();
	var colFromQueryString = qStrPAram.ColumnsToHide;
	if(colFromQueryString!=undefined){
		arrOfPreHiddenColumns = arrOfPreHiddenColumns.concat(colFromQueryString.split(','));
	}
// Array of columns to skip
	var arrOfFieldInternalNamesToSkip = [];
// Call the script
	init_Checkboxes(arrOfPreHiddenColumns,arrOfFieldInternalNamesToSkip);
&lt;/script&gt;

For v1.4 on SP2007 and 1.x on SP2010

&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/ToggleColumnVisibility/ToggleColumnVisibility.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// To &quot;pre uncheck&quot; checkboxes, add names to this array
	var arrOfPreHiddenColumns = ['MyPeoplePicker','My multi line','ID'];
// Array of columns to skip
	var arrOfFieldInternalNamesToSkip = [];
// Array of columns that will not render a checkbox
	var arrDoNotRenderCheckbox = ['LinkTitle','ID'];
	
// Call the script
	init_Checkboxes(arrOfPreHiddenColumns,arrOfFieldInternalNamesToSkip,arrDoNotRenderCheckbox);
&lt;/script&gt;

Regarding the variable “arrOfPreHiddenColumns”:
Refer fields by their FieldInternalName. The “Edit” button and multi line text fields however does not have their FieldIternalName present in the column header and therefore must be addressed by their DisplayName.

Passing columns to hide in the query string:
To hide columns by query string, pass them in the URL like this:
/test/English/Lists/ToggleColumnVisibility/AllItems.aspx?ColumnsToHide=MyNumberColumn,ID

Regarding the variable “arrOfFieldInternalNamesToSkip”:
The array “arrOfFieldInternalNamesToSkip” is used to prevent the creation of checkboxed for those fields. Add the FieldInternalName of the field(s) you don’t want the checkboxes for.

Regarding the variable “arrDoNotRenderCheckbox” (new in v1.4):
The array “arrDoNotRenderCheckbox” is used for fields that should not render as a checkbox. These fields can be prehidden using the array “arrOfPreHiddenColumns” or passed as an argument in the URL.

Download

The sourcecode for the file “ToggleColumnVisibility.js” and the CEWP is found here

Ask if anything is unclear.

Regards
Alexander

Filter a calendar view based on user profile property

I got this request from Carel Schotborgh:

Using WSS 3.0

Not have been able to find it anywhere so, since it is possible to filter a list items (in all event/task/etc view) based on membership in SharePoint group (By Alexander). I would like to request the possibility to filter an Agenda View on a single line text, based on a field of the current user information field (for instance department). I import data into SharePoint list what contains names of people. So users do not create the list items and there are multiple columns with names like Judge1 Judge2 Lawyer etc. As you all know you can’t use [ME] value in a single line text. This can only be used with columns: Created by, Modified by, Assigned to and People picking data. Problem with agenda view is also that it only displays 1 field (in general description of appointment for instance).

What do I want?
Filter (a) specific column(s) on the basis of the current user that is logged on (department field for example) in an agenda view.

The agenda should only show items that match the same text as entered in the department field of the user information field of the user that is currently logged on.

In my case IF Judge1 = Mr. J. Jenkins display it OR IF Judge2 = Mr. J. Jenkins display it. The OR statement is very important since SharePoint also filters with AND statement. So I would like to filter multiple columns with department field (any other also ok, as long I can fill in a value that is connected to the current user).

I already managed to create something that filters all event/tasks/etc list view, searching all the columns based upon the current user department field with or statement idea, but not specific columns. Also in agenda view my code and Alexanders code will not work.

If it is not possible to do this on each specific column it is also ok to search all of the columns since the names in my list are unique for each column. Other columns do not contain their names in such a way anyway. I’m already using my script for the not agenda view and works perfectly except user with slow internet will see the entire list my filter starts working.

Excuse me for long text, but it is complex. Much appreciated any help, suggestion or solution.


Here is one suggestion on how this can be done. It pulls the “Department” from the user profile and searches for a match in one of the fields specified in the script (in the variable “arrOfFieldInternalNames”).

This solution does:

  • Filters a calendar view based on a text retrieved from the current users profile (from People and Groups)
  • Filters with an “OR” statement looking for a match in multiple text fields
  • Handles “single day items” and items spanning over multiple days.
  • Hide the calendar view until it has been filtered

This solution doesn’t:

  • If multiple elements are located in one day, the standard calendar view will display a “x more items” link to expand all items that day. My filter solution will filter the items, but may display a link saying there are “3 more items”, but when clicking the link there may no items to display.

The solution
To keep a nice even background when removing items spanning over multiple days, i had to change the background for the “not in this month items” to white.

Add this code to a CEWP below the calendar view:

&lt;style type=&quot;text/css&quot;&gt;
.ms-cal-nodataMid,.ms-cal-nodataBtm2{
	background-color:#FFFFFF;
}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/interaction.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/stringBuffer.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

// Set variables
listGuid = 'FilterCalendarView'; // Use list Name or List Guid
listBaseUrl = L_Menu_BaseUrl;
userListGuid = &quot;{570D772F-0EAB-45A8-8C54-9CCD4EC6A0AF}&quot;; // The &quot;People and Groups&quot; list
userListBaseUrl = ''; // Modify if on a managed path
// The FieldInternalNames to search for information matching the selected user property
arrOfFieldInternalNames = ['Judge1','Judge2'];

// Hide calendar view until it is filtered
$(&quot;.ms-cal-gempty&quot;).hide();

// Get the UserInfo
var userInfoObj = getUserInfo();
var dep = userInfoObj.Department; // User profile property &quot;Department&quot;

// Find all &quot;relevant&quot; items
var myItems = getMyItemsID(dep,arrOfFieldInternalNames);
// Filter view
filterCalendarView(myItems);

function getMyItemsID(find,findInArr){
	wsBaseUrl = listBaseUrl + '/_vti_bin/';
	var query = &quot;&quot;;
	$.each(findInArr,function(i,fin){
		query += &quot;&lt;Eq&gt;&lt;FieldRef Name='&quot;+fin+&quot;' /&gt;&lt;Value Type='Text'&gt;&quot;+find+&quot;&lt;/Value&gt;&lt;/Eq&gt;&quot;;
		if(i&gt;0)query = &quot;&lt;Or&gt;&quot; + query + &quot;&lt;/Or&gt;&quot;;
	});
	query = &quot;&lt;Where&gt;&quot; + query + &quot;&lt;/Where&gt;&quot;;
	var arrToReturn = [];
	res = queryItems(listGuid,query,['ID']);
	$.each(res.items,function(i,item){
		arrToReturn.push(item.ID);
	});
	return arrToReturn;
}

function filterCalendarView(arrOfIDs){
	$(&quot;.ms-cal-gempty a[href*='DispForm.aspx?ID=']&quot;).each(function(){
		var currID = $(this).attr('href').match(/ID=(d+)/);
		if($.inArray(currID[1],arrOfIDs)==-1){
			// remove
			var thisParentTd = $(this).parents('table:first').parents('td:first');
			var colspan = thisParentTd.attr('colspan');
			if(colspan&gt;1){		
				for(i=1;i&lt;colspan;i++){				
					thisParentTd.after(&quot;&lt;td class='ms-cal-workitem'&gt;&amp;nbsp;&lt;/td&gt;&quot;);
				}
				thisParentTd.replaceWith(&quot;&lt;td class='ms-cal-workitem'&gt;&amp;nbsp;&lt;/td&gt;&quot;);
			}else{
				thisParentTd.html('&amp;nbsp;');			
			}		
		}
	});
// Show calendar view after it has been filtered
$(&quot;.ms-cal-gempty&quot;).show();
}

function getUserInfo(UserId){
wsBaseUrl = userListBaseUrl + '/_vti_bin/';
var uiObj = {};

if(typeof(UserId)==&quot;undefined&quot; || UserId=='')UserId = _spUserId;

var arrOfFields = ['ID', 'Name', 'Title', 'EMail', 'Department', 'JobTitle', 'Notes', 'Picture',
'IsSiteAdmin', 'Created', 'Author', 'Modified', 'Editor', 'SipAddress', 'Deleted'];

var item = getItemById(userListGuid,UserId,arrOfFields);
    if(item != null){
	    for(i=0;i&lt;arrOfFields.length;i++){
	    	if(item[arrOfFields[i]]!=null){
	    		uiObj[arrOfFields[i]] = item[arrOfFields[i]];
	    	}else{
	    		uiObj[arrOfFields[i]] = '';
	    	}
	    }
       	return uiObj;
    }else{
        for(i=0;i&lt;arrOfFields.length;i++){
    		uiObj[arrOfFields[i]] = &quot;User with id &quot; + UserId + &quot; not found.&quot;;
    	}
		return uiObj;
	}
}	
&lt;/script&gt;

Modify the parameters:

  • listGuid: The list name or list Guid of the list to filter.
  • listBaseUrl: The base URL of the list to filter.
  • userListGuid: The list Guid of the user list (People and Groups).
  • userListBaseUrl: The user list base URL – Most likely an empty string “”. If the site resides on a manage path this must be reflected.
  • arrOfFieldInternalNames: Array of the FieldInternalNames to search for a match on the search string-

The jQuery-library is found here. The sourcecode refers to jquery-1.3.2.min.js. If you use another version, please update the reference in the code.

The scripts “interaction.js” and “stringBuffer.js” is created by Erucy and published on CodePlex.

Read here how to add a CEWP to NewForm or EditForm, and how to get the guid for a list.

I do not think this is a “production environment solution” at this stage, but please test it and post back any comments or suggestions and i will try to adapt the script.

Regards
Alexander

Edit SharePoint Field properties, including lookup column list association, with client side code only

20.10.2010 Updated code to add some more features: Edit list properties: “Hidden”, “ShowUser”, “Ordered”, “Direction”. Field properties: ShowInDIP (document information panel) and cross site lookup functionality for a standard SharePoint lookup column. The article is updated and describes the changes.


This code enables you to edit the following using javascript/jQuery only

List properties:

  • Hidden: Hide the list so that it does not appear on the Documents and Lists page, Quick Launch bar, Modify Site Content page, or Add Column page as an option for lookup fields.
  • ShowUser: Specify that names of users are shown in “Created by” and “Modified by” fields.
  • Ordered: Specify that the option to allow users to reorder items in the list is available on the Edit View page for the list.
  • Direction: LTR if the reading order is left-to-right, RTL if it is right-to-left.

Field properties:

  • Hidden: Specifies whether the field is displayed in the list.
  • ReadOnly: Specifies whether values in the field can be modified.
  • Required: Determines whether the field requires values.
  • Show In NewForm: Specifies whether the field is displayed in the form that is used to create list items.
  • Show In DispForm: Specifies whether the field is displayed in the form for displaying list items.
  • Show In EditForm: Specifies whether the field is displayed in the form that is used to edit list items.
  • Show In DIP: Specifies whether the field is displayed in the “Document Information Panel” in compatible Microsoft Office applications. Only available for document libraries.
  • Show In List Settings: Specifies whether the field is displayed in the page for customizing list settings.
  • Show In Version History: Specifies whether the field is displayed in the page for viewing list item versions.
  • Show In View Forms: Specifies whether the field is displayed in pages that are used to view list data.
  • Lookup column web and list association (cross site lookup): Change the web and list association for a lookup column – Note: If you do this, all existing elements in this column will be lost. The cross site option is only available for site collection administrators!

Images:

IMG


IMG


IMG


Disclaimer:
I have removed some list types and some column types, but be careful using this tool. Test this in a “test list” before you use it in your “production environment”. If you edit the wrong field, you could break the list. Use this tool at your own risk!

Create a WebPartPage, insert a CEWP, and paste the code.
You find the code here

Regards
Alexander