首页 > 解决方案 > 在 SharePoint 文档库中查看文件属性而不是文件

问题描述

我在 SharePoint Online 上有一个文档库,其中包含许多元数据列。这些列不适合屏幕上的单个视图,因此我希望用户在下载文件之前先查看文件的属性。

有没有办法改变 SharePoint 库的行为,确保用户在单击文件名时首先查看文件属性?

PS:我知道我可以使用列表,但是在加载了大约 10000 个文档后,我决定将它用作最后的手段。谢谢你。

标签: sharepointlibrariesdocument

解决方案


通过CSR自定义 LinkFilename 字段。

示例代码:

(function () {
    'use strict';

    var CustomWidthCtx = {};

    /**
     * Initialization
     */
    function init() {

        CustomWidthCtx.Templates = {};

        CustomWidthCtx.Templates.Fields = {            
            'LinkFilename': {
                'View': customDisplay
            }
        };

        // Register the custom template
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomWidthCtx);
    }

    /**
     * Rendering template
     */
    function customDisplay(ctx) {
        var currentVal = '';
        //from the context get the current item and it's value 
        if (ctx != null && ctx.CurrentItem != null)
            currentVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

        var el = "<div class='ms-vb  itx' id='" + ctx.CurrentItem.ID + "' app='' ctxname='ctx37'><a title='" + ctx.CurrentItem._ShortcutUrl + "' class='ms-listlink ms-draggable' aria-label='Shortcut file' onfocus='OnLink(this)' href='/Doc4/Forms/EditForm.aspx?ID=" + ctx.CurrentItem.ID + "' target='_blank' DragId='17'>" + ctx.CurrentItem.FileLeafRef + "</a></div>";

        // Render the HTML5 file input in place of the OOTB
        return el;
    }

    // Run our intiialization
    init();

})();

推荐阅读