Force Page Edit Mode
On some SharePoint pages there is no simple way to get to the edit web page view to add/modify/remove web parts. However, SharePoint accepts a QueryString for opening a page in edit mode:
HTTP:\\MYSHAREPOINT?ToolPaneView=2&pagemode=edit
By adding this to the end of any URL where you have rights to edit the page you can then go ahead and edit the page to your hearts content. This is particularly useful when doing modifications to NewForm/EditForm without dissociating the page, or making your own form page.
Data View Web Part Tricks
The first snippet is for pulling unique values down from your data source initially. The second is the much more fun way to make it so the DVWP filter drop downs are unique per column. The filter drop down unique value code snippet is put in to the template and is field type independent. Next we have an XSLT template for changing a string to be all uppercase to make a query comparison case-insensitive effectively, it can also be used for always showing a field as uppercase.
I also pasted some of my older XSLT tidbits related to truncated strings for Read More links and proper string extraction for rendering url and image fields.
Unique Values in initial query <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[not (@Title=preceding-sibling::Row/@Title)]" /> Unique values in filter drop downs <xsl:when test="starts-with($fieldname, '@')" <xsl:variable name="dvt_Rows"> Changed select from $Rows lt;xsl:for-each select="/dsQueryResponse/Rows/Row[not(@*[name()=$dvt_FieldNameNoAtSign]=preceding-sibling::Row/@*[name()=$dvt_FieldNameNoAtSign])]"> <xsl:sort select="@*[name()=$fieldname]" order="ascending" data-type="{$sorttype}" /> <xsl:copy-of select="." /> <xsl:variable> Case Insensitive Comparison (or change case) <xsl:template name="ToUpper"> <xsl:param name="StringValue"/> <xsl:value-of select="translate($StringValue, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> <xsl:template> Field Length Truncate (Read More link and fitting in long content) <a href="@FileRef”> <xsl:variable name="truncate-length” select="40”/> <xsl:value-of select="substring(@Title,1, $truncate-length)”/> <xsl:if test="string-length(@Title) > $truncate-length”> <xsl:text>... xsl:if> </a> Properly format a URL or image field Link: <a href="{substring-before(@URL, ', ')}"> <xsl:value-of select="substring-after(@URL, ', ')"/> </a> Image: <img src="{substring-before(@Field, ', ')}" alt="{substring-after(@Field, ', ')}"/>
Accordion Data View Web Part
{
$(“.accordion”).toggle(
function()
{
$(this).css(“font-size”, “17pt”);
$(“.cssClass”).css(“display”, “none”);
$(this).next().toggle(‘fast’);
},
function()
{
$(this).css(“font-size”, “16px”);
$(this).next().toggle(‘fast’);
});
$(“.accordion”).mouseover(
function()
{
$(this).css(“background”, “black”);
$(this).css(“color”, “white”);
}).mouseout(function()
{
$(this).css(“background”, “white”);
$(this).css(“color”, “black”);
});
});
<xsl:call-template name=”dvt_1.groupheader1″>
<xsl:with-param name=”fieldtitle”>Field
<xsl:with-param name=”fieldname”>Field
<xsl:with-param name=”fieldvalue” select=”$groupheader1″ />
<xsl:with-param name=”fieldtype” select=”‘int'” />
<xsl:with-param name=”nodeset” select=”msxsl:node-set($dvt_Rows)/root//Row[((@Field)=$groupheader1 or ((not(@Field) or @Field=”) and $groupheader1=’ ‘))]” />
<xsl:with-param name=”groupid” select=”‘1′” />
<xsl:with-param name=”displaystyle” select=”‘auto'” />
<xsl:with-param name=”imagesrc” select=”‘/_layouts/images/plus.gif'” />
<xsl:with-param name=”alttext” select=”‘expand'” />
<xsl:with-param name=”altname” select=”‘collapse'” />
<xsl:with-param name=”hidedetail” select=”false()” />
<xsl:with-param name=”showheader” select=”true()” />
<xsl:with-param name=”showheadercolumn” select=”false()” />
xsl:call-template>
<xsl:variable name=”dvt_KeepItemsTogether” select=”false()” />
<xsl:variable name=”dvt_HideGroupDetail” select=”false()” />
<xsl:if test=”(position() >= $FirstRow and position() <= $LastRow) or $dvt_KeepItemsTogether”>
<xsl:if test=”not($dvt_HideGroupDetail)” ddwrt:cf_ignore=”1″>
<xsl:call-template name=”dvt_1.rowview” />
xsl:if>
xsl:if>
</div>
Multiple Entry Single Field
This is a method I came up with to use jQuery to fake an n+1 relationship for one or more columns within a single list item. You can see in the image below that the user is initially presented with the designated fields empty; they have a button for adding the new ‘rows’ in to the fields specified. This is a simple method for basic scenarios where you need a relational style input within a single form.
The code works by adding an event handle to each new text box inserted that is triggered on KeyUp to concatenate the values into a CSV list that is stored in the hidden original field. So if you have added three ‘rows’ you would get something like this saved: “Value1,Value2,Value3,”
To use, insert a content editor web part and edit the [title=”Column” selector to be the display value of the field to treat in this manner.
-
<script type=“text/javascript”>
-
$(document).ready(function()
-
{
-
$(‘[title=”Sub-Project name”]’).css(“display”, “none”);
-
$(‘[title=”Sub-Project Description”]’).css(“display”, “none”);
-
$(‘[title=”Sub-Project name”]’).parent().parent().prev().append(““);
-
$(‘[title=”Sub-Project name”]’).parent().append(“<ul id=’subProjectList’>”);
-
$(‘[title=”Sub-Project Description”]’).parent().append(“”);
-
});
-
function AddProject()
-
{
-
var count = $(‘.subProject’).length;
-
if(count < 5)
-
{
-
$(‘#subProjectList’).append(“<li><input class=’subProject’ type=’text’/></li>”);
-
$(‘.subProject’).bind(‘keyup’, function()
-
{
-
var text = ”;
-
$(‘.subProject’).each(function(i)
-
{
-
var value = $(this).val();
-
text += value;
-
text += ‘,’;
-
});
-
$(‘[title=”Sub-Project name”]’).val(text);
-
});
-
$(‘#subProjectDescriptions’).append(”
- <textarea cols=’40’ rows=’3′ class=’subProjectDescription’/>
“);
SharePoint Search with Pagination
-
/// <summary>
-
/// search sharepoint using a predefined search query
-
/// </summary>
-
/// SQL like sharepoint search query
-
/// SPSite to run against
-
/// rowCount”>Optional: row limit
-
/// <param name=”page”>Optional: page index</param>
-
/// <returns></returns>
-
public DataSet DefinedQuery(string query, SPSite site, int rowCount = 50, int page = 0)
-
{
-
ServerContext srvContext = ServerContext.GetContext(site);
-
int startRow = 0;
-
if (page > 0)
-
{
-
startRow = page*rowCount;
-
rowCount = rowCount * page;
-
}
-
//run query and pass values to allow for pagination
-
{
-
ResultTypes = ResultType.RelevantResults,
-
QueryText = query,
-
RowLimit = rowCount,
-
StartRow = startRow
-
})
-
{
-
try
-
{
-
ResultTableCollection results = runQry.Execute();
-
ResultTable resultTbl = results[ResultType.RelevantResults];
-
//verify we have at least one result to work with
-
if (resultTbl.RowCount >= 1)
-
{
-
//pull results in to our datatable and dataset
-
DataTable tbl = dt.Tables.Add();
-
tbl.Load(resultTbl);
-
}
-
resultTbl.Dispose();
-
}
-
catch (Exception ex)
-
{
-
string msg = ex.Message;
-
}
-
}
-
return dt;
-
}
Extending the size of the Rich Text Editor
/* widens the RTE field control in forms*/
#onetIDListForm, #onetIDListForm .ms-formbody,#onetIDListForm iframe[title=”Rich Text Editor”]{
width:100% !important;
}
/*makes RTE control taller*/
#onetIDListForm iframe[title=”Rich Text Editor”]
{
height:300px !important;
}
/* makes RTE toolbar width match control width */
.ms-long
{
width:100% !important
}
/*removes display of field label above field control and border around field control*/
DIV.ms-formfieldlabelcontainer SPAN.ms-formfieldlabel
{
display:none;
}
.ms-formfieldvaluecontainer
{
border:none !important;
}
/*widens form table altogether with scaling for different resolutions*/
.ms-formtable
{
min-width:900px;
max-width:100%;
}
</style>
width:100% !important;
}
– Maarten