Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Working with wiki pages and filtering is not returning correctly for DVWP display form

$
0
0
I am building a DVWP / Display form for an Enterprise Wiki to display comments on the pages they are entered on following http://chrisstahl.wordpress.com/2012/06/30/comment-functionality-for-news-pages-part-i/ and have set the DFWP as close to the sample code he provides as I can, with the exception of being able to set the query strings variables the way he directs because of the Pages Library set-up. All fields are populating the way they should, I just can't get the filtering to work.

I have run into issues with filtering the Display form according to the page the form is present on because of multiple levels of folders involved in the Pages Library and likely other complications that come with working with the Enterprise Wiki. I have been unable to find a Query String Variable or filter combination that will display any results.

I have used jQuery to re-create the Name Field, but it won't accept it as a way to filter due to the folders.

I have the page ID, through use of the SharePoint:ListItemsProperty Control, however, it won't filter based on that value (I think because of the field formatting being inconsistent when I pass it through the new item form).

Is there a way to filter it directly with Javascript or jQuery? I am new to code and using query strings, both, all my experience previously has been doing everything OOB.

I am doing all my work in SPD, I am unable to import solutions/ features into the the site collection due to issues regarding company policy and managed code.

So, any ideas or a simple way to get the filter to work?

Here is my webpart code:
<ParameterBindings>
         <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
         <ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
         <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
         <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
         <ParameterBinding Name="ListID" Location="None" DefaultValue="{69E762CE-929B-41CC-A4A2-F87C7DBF149F}"/>
     </ParameterBindings>
<DataFields>@Title,Title;@Author,Created By;@Editor,Modified By;@PageID,PageID;@PageTitle,PageTitle;@Comments,Comments;@_Author,Author;@Workflow_x0020_Name,Workflow Name;@NotficationSent,Notfication Sent;@NotificationRecipient,Notification Recipient;@PageID_x003a_Contact_x0020_Name,PageID:Contact Name;@PageID_x003a_Title,PageID:Title;@IDLinkingField,IDLinkingField;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;@ItemChildCount,Item Child Count;@FolderChildCount,Folder Child Count;</DataFields>
<Xsl>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:output method="html" indent="no"/>
    <xsl:decimal-format NaN=""/>
    <xsl:param name="dvt_apos">&apos;</xsl:param>
    <xsl:param name="ManualRefresh"></xsl:param>
    <xsl:param name="ListID">{69E762CE-929B-41CC-A4A2-F87C7DBF149F}</xsl:param>
    <xsl:variable name="dvt_1_automode">0</xsl:variable>
    
    <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
        <xsl:choose>
            <xsl:when test="($ManualRefresh = 'True')">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td valign="top">
                            <xsl:call-template name="dvt_1"/>
                        </td>
                        <td width="1%" class="ms-vb" valign="top">
                            <img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/>
                        </td>
                    </tr>
                </table>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="dvt_1"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template name="dvt_1">
        <xsl:variable name="dvt_StyleName">RepForm3</xsl:variable>
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row "/>
        
        <xsl:variable name="dvt_RowCount" select="count($Rows)"/>
        <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
        <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
        
        <xsl:choose>
            <xsl:when test="$dvt_IsEmpty">
                <xsl:call-template name="dvt_1.empty"/>
            </xsl:when>
            <xsl:otherwise>
                <table border="0" style="width: 64%">
                    <xsl:call-template name="dvt_1.body">
                        <xsl:with-param name="Rows" select="$Rows"/>
                    </xsl:call-template>
                </table>
            </xsl:otherwise>
        </xsl:choose></xsl:template>
    <xsl:template name="dvt_1.body">
        <xsl:param name="Rows"/>
        <xsl:for-each select="$Rows">
            <xsl:call-template name="dvt_1.rowview" />
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="dvt_1.rowview">
        <tr>
            <td>
                <table border="0" cellspacing="0" style="width: 100%">
                    <tr>
                    <td>
                    <table>
                    <tr>
                    <td style="text-align:right;width:8%"><xsl:attribute name="border">1px #bfbfbf</xsl:attribute>
                            <xsl:attribute name="padding">1px</xsl:attribute>
                            <img border="0" src="{@Editor.picture}" width="35" height="40" style="float: right" /></td>
                    <td  class="ms-vb" style="width: 22%">
                    <xsl:value-of select="@Author" disable-output-escaping="yes" />                 </td>   
                    <td  class="ms-vb" style="width: 25%">
                            <xsl:value-of select="@Created" />
                        </td>
                        <td class="ms-vb" style="width:45%"><xsl:value-of select="@Comments" /></td>                        </tr>
                    </table>        
                    </td>
                        </tr>
                    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <tr>
                            <td colspan="99" class="ms-vb">
                                <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>
                            </td>
                        </tr>
                    </xsl:if>
                </table>
            </td>
        </tr>
    </xsl:template>
    <xsl:template name="dvt_1.empty">
        <xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
        <table border="0" width="100%">
            <tr>
                <td class="ms-vb">
                    <xsl:value-of select="$dvt_ViewEmptyText"/>
                </td>
            </tr>
        </table>
    </xsl:template></xsl:stylesheet>    
Here is how I populate it (recommendations on better methods appreciated)
<script type="text/javascript" src="/Style Library/scripts/jquery.SPServices-0.7.1a.min.js"></script>

<script type="text/javascript">
// File to set Filters and html for wiki page comments web part must load last

// Limit characters
    function limitChars(textid, limit, infodiv){
        var text = $('#'+textid).val();    
        var textlength = text.length;
            if(textlength > limit) {
            $('#' + infodiv).html(''+limit+' limit reached');
            $('#'+textid).val(text.substr(0,limit));
            return false;
            }
            else {
            $('#' + infodiv).html(''+ (limit - textlength) +' characters left');
            return true;
            }}
            
            //set character Limit
    $(function(){
        $(".FormFieldNewsComments > span > textarea[title='Comments']").keyup
        (function()
        {limitChars(".FormFieldNewsComments > span > textarea[title='Comments']", 300, "LimitInfo");
        })
        }); 
            //Set form fields
    $(document).ready(function() {
        var fileloc = location.pathname.substr(17) // Get the page filename
        var PageTitle = $('.wikipagenamediv').html(); // Get the page title
        var PageTitleT = $.trim(PageTitle);
        var PageIDvalue = _spPageContextInfo.pageItemId;
    $(".FormFieldNewsTitle > span > input[title='Title']").val(fileloc); // insert page filename in a CSS hidden formfield
    $(".FormFieldPageTitle > span > input[title='PageTitle']").val(PageTitleT); // insert pages title in a CSS hidden formfield
    $("select[title='PageID']").val(PageIDvalue); // If less than 20 items i Pages bibl, lägger in ID nr som en selected i DD
    $("input[title='PageID']").val(PageIDvalue);  // If 20 or more items in Pages lib
        
        });
 $().SPServices({
      operation: "GetListItems",
      async: false,
      listName: "{0d1170bb-5edb-46b8-924c-7f5f369e1a83}", //wiki library GUID
      CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /><FieldRef Name='PageTitle' />",
      CAMLQuery: "<eq><fieldref Name='PageID'/><value Type='Text'>_spContext.pageItemId</value></eq>",
      completefunc: null, 
        debug: true });
</script>

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>