【问题标题】:Custom "New Item or Edit This list" button自定义“新建项目或编辑此列表”按钮
【发布时间】:2019-11-23 03:12:44
【问题描述】:

我需要创建一个自定义的“新建项目或编辑此列表”按钮,以便快速编辑 SP 列表视图。以下是详细信息:

  • 我需要阻止用户创建新项目。我只需要“编辑此列表”和“停止编辑此列表”功能。
  • 我可以通过 CSS 轻松隐藏“新项目”按钮,但“或”文本仍然存在。
  • 理想情况下,我正在寻找完全相同的功能(这意味着“停止编辑此列表”功能只会在网格打开并处于活动状态后出现)。

任何可以实现此目的的自定义 HTML 按钮的想法都会非常有帮助。

【问题讨论】:

  • 将“新项目”按钮和“或”放在跨度内,并隐藏跨度而不仅仅是按钮
  • 你能详细说明一下吗?这些控件由 SharePoint 提供 OOTB。您是否建议我通过 SPD 或其他方式编辑 html?如果是这样,我怎样才能在 SPD 中找到这个 HTML 的 sn-p?

标签: javascript sharepoint


【解决方案1】:

将以下代码添加到列表视图页面的脚本编辑器 Web 部件中。

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        OnPostRender: function(ctx) {
            if($("a[title^='Edit this list using Quick Edit mode']").length>0){
                var editBtnHtml=$("a[title^='Edit this list using Quick Edit mode']")[0].outerHTML+" this list";
                $(".ms-list-addnew").html(editBtnHtml); 
            }                   
        }
    });
});
</script> 

【讨论】:

    【解决方案2】:

    作为参考,这是我用来生成 HTML 按钮和 JS 函数的代码。效果很好。

    <!DOCTYPE html>
    <html>
    <body>
    <table>
    <tr>
    <td>
    <button id="quickedit" onclick="QuickEditFunction();return false;"><h4 id="attestheader">Edit Data</h4></button>
    
    <script>
    function QuickEditFunction()
    {
    InitGridFromView(window['WPQ4SchemaData'].View);
    }
    </script>
    </td>
    
    
    <td>
    <body>
    <button id="quickedit" onclick="ExitGridFunction(); return false;"><h4 id="attestheader">Save Changes</h4></button>
    
    <script>
    function ExitGridFunction() 
    {
    ExitGrid(window['WPQ4SchemaData'].View);
    }  
    </script>
     </td>
    </tr>
    </table>
    </body>
    </html>
    

    请注意,WPQ4SchemaData 引用必须更改以反映您的列表 Web 部件数字 ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 2014-05-16
      相关资源
      最近更新 更多