如何自定义 SharePoint 列表列聚合(总计)计算?
我有一个“单行文本”类型的 SharePoint 列表列。开箱即用的 SharePoint 仅提供显示此列类型的“计数”总计的功能。我希望能够对数据执行自定义聚合(特别是对作为文本保存的数字数据进行求和,以克服 此缺陷)。
我找到了使用 XSLT 和 Javascript 但我相信这两种方法在数据分页时都会失败(仅聚合屏幕上显示的列表内容的子集)。
我想保留 ListViewWebPart(渲染、排序、过滤、视图定义、操作菜单等)但添加此功能。我该怎么做?
I have a SharePoint list column of type 'Single line of text'. Out of the box SharePoint only provides the ability to display a 'Count' total for this column type. I would like to be able to perform a custom aggregation on the data (specifically to sum numeric data held as text to overcome this deficiency).
I have found examples for doing something similar for calculated columns using XSLT and Javascript but I believe that both of these approaches fail where the data is paginated (only aggregating the subset of the list content displayed on screen).
I want to retain the functionality of the ListViewWebPart (rendering, sorting, filtering, view definition, action menus etc.) but add this functionality. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对总计进行的唯一操作是:
平均值;数数;最大限度;最小;和;标准差;方差
不确定如何计算其他内容。
The only things you can do with totals are:
Average; Count; Max; Min; Sum; Standard Deviation; Variance
Not sure how to calculate anything else.
我还没有机会完全测试它,但这是我能想到的最好的方法:
创建一个包含两个控件的
WebPart
:ViewToolBar
,其上下文为要显示的列表/视图Literal
这将渲染为原始列表/视图。
呈现
WebPart
时,从视图中获取项目,并将RowLimit
指定为最大值,以便检索其中的所有项目(而不仅仅是第一页)。迭代项目,以合适的数据类型计算总计以保持精度。
将总计呈现为 HTML 中的隐藏值,并使用 Javascript 覆盖呈现的
Count
总计,例如 此处描述的方法。代码的粗略草图:
请注意,这并不能解决“修改视图”屏幕仅将
Count
显示为文本列总数的问题。此外,视图初始呈现和检索聚合项目之间的列表更改也有可能会在总数和显示的项目之间产生差异。I've not had a chance to fully test it but this is the best I could come up with:
Create a
WebPart
which contains two controls:ViewToolBar
with the context of the list/view to be displayedLiteral
containing the rendered HTML of the view to be displayedThis will then render as the original list/view.
On rendering the
WebPart
, get the items from the view, specifying theRowLimit
as the maximum value so that all items in are retrieved (not just the first page).Iterate over the items, calculating the total in a suitable data type to retain precision.
Render the total as a hidden value in the HTML and overwrite the rendered
Count
total with Javascript such as by the method described here.A rough sketch of the code:
Note that this doesn't solve the problem with the Modify View screen only showing
Count
as a total for text columns. Also there is a possibility that changes to the list between the initial rendering by the view and the retrieval of the items for aggregation could produce discrepancies between the total and the displayed items.