list 如何在 SharePoint 列表中显示计算列的总计?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1639893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 01:24:32  来源:igfitidea点击:

How can I display a total for a calculated column in a SharePoint list?

sharepointlistsum

提问by Rachel

I have a column, B, that is calculated based on another column, A. At the top of the list, I'd like to display the sum of B. When I look in the Totals section in the Create/Modify a Column screen, I only see column A (actually, I only see all the non-calculated columns), so I can't choose to sum column B.

我有一个列 B,它是根据另一列 A 计算的。在列表的顶部,我想显示 B 的总和。当我查看“创建/修改列”屏幕的“总计”部分时,我只看到A列(实际上,我只看到所有未计算的列),所以我不能选择对B列求和。

Is there a way to display a total for column B?

有没有办法显示 B 列的总数?

回答by Rachel

I found something that feels like a hack, but it works:

我发现了一些感觉像黑客的东西,但它有效:

  1. Using a web browser, edit your desired list to use “Totals” on at least one column in your list.
  2. Open your desired SharePoint site in SharePoint Designer.
  3. In the Folder List view, find your desired list in the Lists folder.
  4. Open AllItems.aspx (or whatever view you want to edit).
  5. In the Web Parts inspector, Web Parts tab, click the "UsernameGallery" and the Web Part List below that will display a list that includes a Content Editor Web Part (CEWP).
  6. Drag the CEWP into the AllItems.aspx (or whatever) view you have open.
  7. Save the aspx file.
  8. Go to this JQuery web pageand copy whichever script you're interested in to the clipboard.
  9. Go to your SharePoint list using a web browser.
  10. You'll see a line of text there now, where you put the CEWP: "To add content, open the tool pane and then click Rich Text Editor." Click on the "open the tool pane" link.
  11. Click the Source Editor button on the right.
  12. Paste the script in the clipboard into the Source Editor window.
  13. Change the "var col = 4; //which column to sum" line so that the column number is the one you want to sum.
  14. Click the Save button and then the OK button in the bottom right.
  1. 使用 Web 浏览器,编辑所需的列表以在列表中的至少一列上使用“总计”。
  2. 在 SharePoint Designer 中打开所需的 SharePoint 网站。
  3. 在文件夹列表视图中,在列表文件夹中找到所需的列表。
  4. 打开 AllItems.aspx(或您想要编辑的任何视图)。
  5. 在 Web 部件检查器的 Web 部件选项卡中,单击“用户名库”和下面的 Web 部件列表,该列表将显示一个包含内容编辑器 Web 部件 (CEWP) 的列表。
  6. 将 CEWP 拖到您打开的 AllItems.aspx(或其他)视图中。
  7. 保存 aspx 文件。
  8. 转到此 JQuery 网页并将您感兴趣的任何脚本复制到剪贴板。
  9. 使用 Web 浏览器转到您的 SharePoint 列表。
  10. 您现在将在那里看到一行文本,您将 CEWP 放在其中:“要添加内容,请打开工具窗格,然后单击富文本编辑器。” 单击“打开工具窗格”链接。
  11. 单击右侧的“源代码编辑器”按钮。
  12. 将剪贴板中的脚本粘贴到源代码编辑器窗口中。
  13. 更改“var col = 4; //要求和的列”行,以便列号是您要求和的列号。
  14. 单击“保存”按钮,然后单击右下角的“确定”按钮。

Voila!

瞧!

Unfortunately, this solution is very brittle. If you make any changes to the page in SharePoint Designer and save the aspx file again, the script code that you put in the CEWP is lost and you have to re-paste it back in again. To make it less brittle, you can just reference the code in a separate file. To do this, remove the code from the CEWP's Source Editor, save the code as a ".js" file in another SharePoint list (e.g., create a new one called "Resources"), copy the URL of that file, and paste the URL into the text box under "To link to a text file, type a URL".

不幸的是,这个解决方案非常脆弱。如果您对 SharePoint Designer 中的页面进行任何更改并再次保存 aspx 文件,则您放入 CEWP 的脚本代码将丢失,您必须重新将其重新粘贴回来。为了使它不那么脆弱,您可以只在单独的文件中引用代码。为此,请从 CEWP 的源代码编辑器中删除代码,将代码另存为另一个 SharePoint 列表中的“.js”文件(例如,创建一个名为“资源”的新文件),复制该文件的 URL,然后粘贴将 URL 插入“要链接到文本文件,请键入 URL”下的文本框。

回答by Nerudo

If you are using a SharePoint data view you can display the count of a column using XSL

如果您使用的是 SharePoint 数据视图,则可以使用 XSL 显示列的计数

< xsl:value-of select="sum(/dsQueryResponse/Rows/Row/@ColumnName)" /> 

In your case the code will have Column B eg:

在您的情况下,代码将包含 B 列,例如:

< xsl:value-of select="sum(/dsQueryResponse/Rows/Row/@column B)" />