Content Query Webpart and Data View Webpart – Modal Dialogs
Requirement
We have a content query webpart that displays information from a list on a subsite. When a user clicks on a link on the webpart, we want the link to open in a Modal dialog.
Solution
- Open SharePoint Designer 2010
- Go to All Files -> Style Library -> XSL Style Sheets -> ItemStyle.xsl -> Modify
- Copy one of the existing templates, e.g. Default, change the name and modify the XSL according to your needs.
Here is a simple example, that I created for ‘Job Vacancies’.
Note the bits in blue where javascript is used to force the links to open in a dialog window.
<xsl:template name=”JobVacancy” match=”Row[@Style='JobVacancy']” mode=”itemstyle”>
<xsl:variable name=”Created”>
<xsl:value-of select=”ddwrt:FormatDateTime(string(@Created) ,1033 ,’dd/MM/yyyy’)” />
</xsl:variable>
<xsl:variable name=”_DCDateCreated”>
<xsl:value-of select=”ddwrt:FormatDateTime(string(@_DCDateCreated) ,1033 ,’dd/MM/yyyy’)” />
</xsl:variable>
<xsl:variable name=”SafeLinkUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeLink”>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”SafeImageUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
<xsl:with-param name=”UrlColumnName” select=”‘ImageUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”DisplayTitle”>
<xsl:call-template name=”OuterTemplate.GetTitle”>
<xsl:with-param name=”Title” select=”@Title”/>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”LinkTarget”>
<xsl:if test=”@OpenInNewWindow = ‘True’” >_blank</xsl:if>
</xsl:variable>
<div id=”linkitem” class=”item”>
<xsl:if test=”string-length($SafeImageUrl) != 0″>
<div class=”image-area-left”>
<a href=”{$SafeLinkUrl}” target=”{$LinkTarget}” title=”{$DisplayTitle}”>
<xsl:value-of select=”$_DCDateCreated”/> – <xsl:value-of select=”$DisplayTitle”/>
</a>
</div>
</xsl:if>
<div class=”link-item”>
<xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/>
<script type=”text/javascript”>
function ModalDialog(url) {
var options = {
url: url,
title: “Job Vacancies”,
allowMaximize: true,
showClose: true,
width: 800,
height: 600,
dialogReturnValueCallback: silentCallback};
SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallback(dialogResult, returnValue) {
}
function refreshCallback(dialogResult, returnValue) {
SP.UI.Notify.addNotification(‘Operation Successful!’);
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
</script>
<a href=”javascript:ModalDialog(‘{$SafeLinkUrl}’)” target=”{$LinkTarget}” title=”{$DisplayTitle}”>
<xsl:value-of select=”$_DCDateCreated”/> – <xsl:value-of select=”$DisplayTitle”/>
</a>
<div class=”description”>
<xsl:value-of select=”@Description” />
</div>
</div>
</div>
</xsl:template>
You can also use the same bit of code to force links in your data view web part to open in a dialog window.
- Edit Webpart properties of your Data View Web Part
- Under Data View Properties -> Click on XSL Editor
- Copy the entire contents to a code editor like Visual Studio or Notepad++.
- Search for the string ‘a href’ – there should only be 1 string.
- Just above the line ‘<a href….”>
- Add in the following code:
<script type=”text/javascript”>
function ModalDialog(url) {
var options = {
url: url, title: “<change this to your title>”,
allowMaximize: true,
showClose: true,
width: 800,
height: 600,
dialogReturnValueCallback: silentCallback};
SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallback(dialogResult, returnValue) {
}
function refreshCallback(dialogResult, returnValue) {
SP.UI.Notify.addNotification(‘Operation Successful!’);
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
</script>
- Next, modify the URL so that it looks like this:
<a href=”javascript:ModalDialog2(‘http://sharepoint/DispForm.aspx?ID={@ows_ID}‘)“>
- Copy the XSL back to the webpart and save.
Your links should now open in a dialog window.
Categories
Recent Posts
- Save document library as template option not available
- Short break
- Speed up SharePoint using the IIS Blobcache
- Could not generate mail report.An exception occurred while executing a Transact-SQL statement or batch.No global profile is configured. Specify a profile name in the @profile_name parameter.
- Microsoft SharePoint is not supported with version 4.0.30319.296 of the Microsoft .Net Runtime.
Popular Posts
- SharePoint Keeps Prompting for Credentials Problem SharePoint keeps prompting you for credentials in the following scenarios: You ...
- Security Token Service Application- Broken Problem Had an issue today on one of my developer's VMs. ...
- User Profile Service Stuck on Starting Problem You have followed Harbar's Rational Guide to setting up the ...
- Event 8313 Topology – Load Balancer EndpointFailure – SearchService.svc Problem Encountered the following error while analysing the logs on our ...
- Event 6398 and 5586 SharePoint Foundation Problem Event logs were getting filled with the following errors: Event 5586, ...
- The security validation for this page is invalid Problem: After applying SharePoint 2010 Service Pack 1 and June 2011 ...
- The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. Problem You install .NET Framework 4.0 on your SharePoint 2010 WFE ...
- Start a workflow using PowerShell Requirement Start a workflow on all / specific items in a ...
- Using Export-SPWeb to export libraries / lists This is a simple one but many people get the ...
- Unable to change User Profile Service Account Problem So you made a mistake by trying to change the ...
Tags
Backup and Restore Branding Content Management Content Organizer database Debugging Document Conversion Service DPM Event 7362 Expiration Policy IIS InfoPath Information Management Javascript KB2266203 Masterpage Migration Mysite OCS Office Page Layouts PowerPivot Powershell RBS Records Center Regional Settings Search Search Center Security Send-to Connection SharePoint Diagnostic Studio SharePoint Manager Solutions SPD Uploading Usage and Health Data Collection User Profile Service Visual Upgrade Web Analytics Web Content Management Webdav Webparts Workflow WSS XSLT
