如何修改 sharepoint 2013 列表列标题? [英] How could I modify sharepoint 2013 list column title?
问题描述
我希望同一列在不同的视图中显示不同的标题,只有一个列表.所以我在 view.aspx 中附加了一个 jquery 脚本.
I want the same column display different title in different views with only one list. So I append a jquery script in my view.aspx.
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript" src="/_layouts/15/Library/js/jquery-1.9.1.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$('[id^=diidSort][id$=company]').text('com');
});
</script>
它有效,但是当我单击列升序或降序然后刷新页面时.专栏标题恢复为原始文本.我该如何解决?
It works,but when I click column ascending or descending then refresh page. the column title restore to original text. How could I fix it?
推荐答案
由于是 SharePoint 2013 环境,建议采用以下方式:
Since it is a SharePoint 2013 environment, the following approach is suggested:
- 创建呈现模板以呈现自定义列标题在列表视图中
- 在视图"页面中更新列表视图 Web 部件
SharePoint 2013 引入了客户端呈现框架 (CSR),用于允许使用 HTML/JavaScript 定义 SharePoint 列表视图的呈现逻辑的列表视图.
SharePoint 2013 introduces client side rendering framework (CSR) for List View that allows to define the rendering logic of SharePoint list views using HTML/JavaScript.
以下示例演示如何为列表视图中的 Title
列呈现自定义标题:
The following example demonstrates how to render the custom title for Title
column in List View:
(function () {
function preTaskFormRenderer(renderCtx) {
modifyHeaderData(renderCtx);
}
function modifyHeaderData(renderCtx)
{
var viewTitle = renderCtx.viewTitle;
var linkTitleField = renderCtx.ListSchema.Field[1];
linkTitleField.DisplayName = viewTitle + ':' + linkTitleField.DisplayName;
}
function registerRenderer()
{
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.OnPreRender = preTaskFormRenderer;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();
如何应用更改
- 将指定的脚本(让其命名为
TaskForm.js
)上传到SharePoint网站资产
库 - 在编辑模式下打开视图"页面并转到列表视图 Web 部件属性"
- 指定位于
Miscellaneous
组下的JS Link
属性:~sitecollection/SiteAssets/TaskForm.js
(见图 1) - 保存更改并根据需要为每个查看"页面重复步骤 2-4
- Upload the specified script (lets name it
TaskForm.js
) into SharePointSite Assets
library - Open View page in edit mode and go to List View web part properties
- Specify
JS Link
property located underMiscellaneous
group:~sitecollection/SiteAssets/TaskForm.js
(see pic. 1) - Save changes and repeat steps 2-4 for every View page if needed
How to apply changes
图 1. JS 链接属性
Fig 1. JS Link property
这篇关于如何修改 sharepoint 2013 列表列标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!