Sharepoint 从SPFieldCalculated派生的自定义字段类型

Sharepoint 从SPFieldCalculated派生的自定义字段类型,sharepoint,sharepoint-2007,moss,Sharepoint,Sharepoint 2007,Moss,我正在尝试创建一个自定义字段类型,它将基于同一列表中的另一个字段显示值。基本上,根据源列的值显示一些图像 由于此列完全基于另一列派生其数据,因此我需要确保列值未存储在数据库中 所以,我想我需要创建一个自定义字段类型,它派生自SPFieldComputed类 但是,当我尝试这样做时,会收到一条错误消息 类型“Microsoft.SharePoint.SPFieldComputed”未定义构造函数 如何创建从SPFieldComputed派生的自定义字段tpye? 如果这不可能,至少有人能告诉我如何

我正在尝试创建一个自定义字段类型,它将基于同一列表中的另一个字段显示值。基本上,根据源列的值显示一些图像

由于此列完全基于另一列派生其数据,因此我需要确保列值未存储在数据库中

所以,我想我需要创建一个自定义字段类型,它派生自SPFieldComputed类

但是,当我尝试这样做时,会收到一条错误消息 类型“Microsoft.SharePoint.SPFieldComputed”未定义构造函数

如何创建从SPFieldComputed派生的自定义字段tpye?
如果这不可能,至少有人能告诉我如何满足我的要求吗?

恐怕我以前没有尝试过创建自定义字段。。不过,我有一个建议可能会奏效。该字段可以只是一个图片字段。您可以使用列表中的事件接收器,每当目标字段发生更改时,该接收器将计算所需字段。这有点冗长,但是如果你不使用自定义字段的方法,这可能会发生。

恐怕我以前没有尝试过创建自定义字段。。不过,我有一个建议可能会奏效。该字段可以只是一个图片字段。您可以使用列表中的事件接收器,每当目标字段发生更改时,该接收器将计算所需字段。这有点冗长,但如果您无法使用自定义字段的方式,则可能会出现这种情况。

假设此列实际上只用于显示,我可以想出两种方法来帮助您:

使用计算列创建HTML,然后使用JavaScript将其打开: 您可能可以使用SharePoint Designer和DataForm Web部件执行此操作:
假设本专栏仅用于显示,我可以想出两种方法来帮助您:

使用计算列创建HTML,然后使用JavaScript将其打开: 您可能可以使用SharePoint Designer和DataForm Web部件执行此操作:
你想从SPField得到SPField没有的东西吗?我将通过基于SPField创建自定义字段来解决此问题,然后我将:

1在字段编辑器中注册事件接收器,并使用它设置字段的值

2如果要预览“编辑/新建表单”中的值,请在字段控件中计算该值。这要求您的字段排序低于您的值所基于的字段,否则您将根据旧数据计算值


如果重新计算,我还建议您保存计算值。如果要在列表视图中显示数据,这是唯一合理的方法,因为渲染模式是用CAML而不是C编写的。

是否需要从SPFieldComputed中获得SPField没有的内容?我将通过基于SPField创建自定义字段来解决此问题,然后我将:

1在字段编辑器中注册事件接收器,并使用它设置字段的值

2如果要预览“编辑/新建表单”中的值,请在字段控件中计算该值。这要求您的字段排序低于您的值所基于的字段,否则您将根据旧数据计算值


如果重新计算,我还建议您保存计算值。如果您希望在列表视图中显示数据,这是唯一合理的方法,因为您使用CAML而不是C编写渲染图案。

为列表创建渲染图案实际上可以获得更多里程

这将允许您完全更改列在html方面的显示方式,而无需添加计算字段

Alternativley,您也可以考虑在StimaXML中使用自定义字段定义来做一些非常时髦的事情。例如,我在一个普通的发布页面库中包含一个名称字段的模式xml

<Field ID="{9d30f126-ba48-446b-b8f9-83745f322ebe}" ReadOnly="TRUE" Type="Computed" Name="LinkFilenameNoMenu" DisplayName="Name" DisplayNameSrcField="FileLeafRef" Filterable="FALSE" AuthoringInfo="(linked to document)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkFilenameNoMenu" FromBaseType="TRUE"><FieldRefs><FieldRef Name="FileLeafRef" /><FieldRef Name="FSObjType" /><FieldRef Name="Created_x0020_Date" /><FieldRef Name="FileRef" /><FieldRef Name="File_x0020_Type" /><FieldRef Name="ContentTypeId" /><FieldRef Name="PermMask" /><FieldRef Name="CheckoutUser" /><FieldRef Name="IsCheckedoutToLocal" /></FieldRefs><DisplayPattern><IfEqual><Expr1><LookupColumn Name="FSObjType" /></Expr1><Expr2>1</Expr2><Then><FieldSwitch><Expr><GetVar Name="RecursiveView" /></Expr><Case Value="1"><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /></Case><Default><SetVar Name="UnencodedFilterLink"><SetVar Name="RootFolder"><HTML>/</HTML><LookupColumn Name="FileRef" /></SetVar><SetVar Name="FolderCTID"><FieldSwitch><Expr><ListProperty Select="EnableContentTypes" /></Expr><Case Value="1"><Column Name="ContentTypeId" /></Case></FieldSwitch></SetVar><FilterLink Default="" Paged="FALSE" /></SetVar><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><GetVar Name="UnencodedFilterLink" HTMLEncode="TRUE" /><HTML><![CDATA[" onclick="javascript:EnterFolder(']]></HTML><ScriptQuote NotAddingQuote="TRUE"><GetVar Name="UnencodedFilterLink" /></ScriptQuote><HTML><![CDATA[');return false;">]]></HTML><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML></Default></FieldSwitch></Then><Else><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><Field Name="ServerUrl" URLEncodeAsURL="TRUE" /><HTML><![CDATA[" onclick="return DispEx(this,event,']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTransform" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrAcceptType"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrHandleUrl"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrProgId"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="DefaultItemOpen" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><MapToControl><Column Name="HTML_x0020_File_x0020_Type" /><HTML>|</HTML><Column Name="File_x0020_Type" /></MapToControl></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="HTML_x0020_File_x0020_Type" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="GetServerFileRedirect"><Field Name="ServerUrl" /><HTML>|</HTML><Column Name="HTML_x0020_File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="CheckoutUser" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><UserID AllowAnonymous="TRUE" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="ForceCheckout" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="IsCheckedoutToLocal" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="PermMask" /></ScriptQuote><HTML><![CDATA[')">]]></HTML><UrlBaseName HTMLEncode="TRUE"><LookupColumn Name="FileLeafRef" /></UrlBaseName><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML><IfNew Name="Created_x0020_Date"><HTML><![CDATA[<IMG SRC="/_layouts/1033/images/new.gif" alt="]]></HTML><HTML>New</HTML><HTML><![CDATA[">]]></HTML></IfNew></Else></IfEqual></DisplayPattern></Field>

令人讨厌,但很有效。

为列表创建一个列表,实际上可能会让你获得更多的里程数

这将允许您完全更改列在html方面的显示方式,而无需添加计算字段

Alternativley,您也可以考虑在StimaXML中使用自定义字段定义来做一些非常时髦的事情。例如,我在一个普通的发布页面库中包含一个名称字段的模式xml

<Field ID="{9d30f126-ba48-446b-b8f9-83745f322ebe}" ReadOnly="TRUE" Type="Computed" Name="LinkFilenameNoMenu" DisplayName="Name" DisplayNameSrcField="FileLeafRef" Filterable="FALSE" AuthoringInfo="(linked to document)" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkFilenameNoMenu" FromBaseType="TRUE"><FieldRefs><FieldRef Name="FileLeafRef" /><FieldRef Name="FSObjType" /><FieldRef Name="Created_x0020_Date" /><FieldRef Name="FileRef" /><FieldRef Name="File_x0020_Type" /><FieldRef Name="ContentTypeId" /><FieldRef Name="PermMask" /><FieldRef Name="CheckoutUser" /><FieldRef Name="IsCheckedoutToLocal" /></FieldRefs><DisplayPattern><IfEqual><Expr1><LookupColumn Name="FSObjType" /></Expr1><Expr2>1</Expr2><Then><FieldSwitch><Expr><GetVar Name="RecursiveView" /></Expr><Case Value="1"><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /></Case><Default><SetVar Name="UnencodedFilterLink"><SetVar Name="RootFolder"><HTML>/</HTML><LookupColumn Name="FileRef" /></SetVar><SetVar Name="FolderCTID"><FieldSwitch><Expr><ListProperty Select="EnableContentTypes" /></Expr><Case Value="1"><Column Name="ContentTypeId" /></Case></FieldSwitch></SetVar><FilterLink Default="" Paged="FALSE" /></SetVar><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><GetVar Name="UnencodedFilterLink" HTMLEncode="TRUE" /><HTML><![CDATA[" onclick="javascript:EnterFolder(']]></HTML><ScriptQuote NotAddingQuote="TRUE"><GetVar Name="UnencodedFilterLink" /></ScriptQuote><HTML><![CDATA[');return false;">]]></HTML><LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" /><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML></Default></FieldSwitch></Then><Else><HTML><![CDATA[<A onfocus="OnLink(this)" HREF="]]></HTML><Field Name="ServerUrl" URLEncodeAsURL="TRUE" /><HTML><![CDATA[" onclick="return DispEx(this,event,']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTransform" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrAcceptType"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrHandleUrl"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="HtmlTrProgId"><Column Name="File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="DefaultItemOpen" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><MapToControl><Column Name="HTML_x0020_File_x0020_Type" /><HTML>|</HTML><Column Name="File_x0020_Type" /></MapToControl></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="HTML_x0020_File_x0020_Type" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ServerProperty Select="GetServerFileRedirect"><Field Name="ServerUrl" /><HTML>|</HTML><Column Name="HTML_x0020_File_x0020_Type" /></ServerProperty></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Column Name="CheckoutUser" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><UserID AllowAnonymous="TRUE" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><ListProperty Select="ForceCheckout" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="IsCheckedoutToLocal" /></ScriptQuote><HTML><![CDATA[',']]></HTML><ScriptQuote NotAddingQuote="TRUE"><Field Name="PermMask" /></ScriptQuote><HTML><![CDATA[')">]]></HTML><UrlBaseName HTMLEncode="TRUE"><LookupColumn Name="FileLeafRef" /></UrlBaseName><IfEqual><Expr1><GetVar Name="ShowAccessibleIcon" /></Expr1><Expr2>1</Expr2><Then><HTML><![CDATA[<img src="/_layouts/images/blank.gif" class="ms-hidden" border=0 width=1 height=1 alt="]]></HTML><HTML>Use SHIFT+ENTER to open the menu (new window).</HTML><HTML><![CDATA[">]]></HTML></Then></IfEqual><HTML><![CDATA[</A>]]></HTML><IfNew Name="Created_x0020_Date"><HTML><![CDATA[<IMG SRC="/_layouts/1033/images/new.gif" alt="]]></HTML><HTML>New</HTML><HTML><![CDATA[">]]></HTML></IfNew></Else></IfEqual></DisplayPattern></Field>

讨厌,但很有效。

在fieltypexml中,您可以在模板的CAML中添加一个LookupColumn。 在您的问题中,您可以使用字段类型文本,并在DisplayPattern中编写如下内容

<RenderPattern Name="DisplayPattern">
    <HTML><![CDATA[<img src="]]></HTML>
      <LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
    <HTML><![CDATA["/>]]></HTML>
</RenderPattern>

在fieltype xml中,您可以在模板的CAML中添加一个LookupColumn。 在您的问题中,您可以使用字段类型文本,并在DisplayPattern中编写如下内容

<RenderPattern Name="DisplayPattern">
    <HTML><![CDATA[<img src="]]></HTML>
      <LookupColumn Name="FileLeafRef" HTMLEncode="TRUE" />
    <HTML><![CDATA["/>]]></HTML>
</RenderPattern>

不幸的是,无法从SPCalculatedField类继承,该类 这就是您收到该错误的原因:

Windows SharePoint Services 3.0确实如此 不支持从此继承 班级

为了在2007年显示基于另一列值的图像,您必须在fldtypes…xml中进行一些令人不快的CAML工作,正如@davida所提到的。这里是一个很好的起点:

我还将天真地提到,可能会有具有此功能的商业替代方案,我可能会帮助创建其中一个,并且可能在这里提到:

不幸的是,无法从SPCalculatedField类继承,这就是您收到该错误的原因:

Windows SharePoint Services 3.0确实如此 不支持从此继承 班级

为了在2007年显示基于另一列值的图像,您必须在fldtypes…xml中进行一些令人不快的CAML工作,正如@davida所提到的。这里是一个很好的起点:

我还将天真地提到,可能会有具有此功能的商业替代方案,我可能会帮助创建其中一个,并且可能在这里提到: