如何自定义 SharePoint 列表列聚合(总计)计算?

发布于 2024-08-13 10:30:19 字数 852 浏览 4 评论 0原文

我有一个“单行文本”类型的 SharePoint 列表列。开箱即用的 SharePoint 仅提供显示此列类型的“计数”总计的功能。我希望能够对数据执行自定义聚合(特别是对作为文本保存的数字数据进行求和,以克服 此缺陷)。

我找到了使用 XSLTJavascript 但我相信这两种方法在数据分页时都会失败(仅聚合屏幕上显示的列表内容的子集)。

我想保留 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疏忽 2024-08-20 10:30:19

您可以对总计进行的唯一操作是:

平均值;数数;最大限度;最小;和;标准差;方差

不确定如何计算其他内容。

The only things you can do with totals are:

Average; Count; Max; Min; Sum; Standard Deviation; Variance

Not sure how to calculate anything else.

怀念你的温柔 2024-08-20 10:30:19

我还没有机会完全测试它,但这是我能想到的最好的方法:

创建一个包含两个控件的 WebPart

  1. 一个 ViewToolBar ,其上下文为要显示的列表/视图
  2. 包含要显示的视图的渲染 HTML 的 Literal

这将渲染为原始列表/视图。

呈现 WebPart 时,从视图中获取项目,并将 RowLimit 指定为最大值,以便检索其中的所有项目(而不仅仅是第一页)。

迭代项目,以合适的数据类型计算总计以保持精度。

将总计呈现为 HTML 中的隐藏值,并使用 Javascript 覆盖呈现的 Count 总计,例如 此处描述的方法

代码的粗略草图:

public sealed class TextAggregatingWebPart : WebPart {
  protected override void CreateChildControls() {
    base.CreateChildControls();

    var web = SPContext.Current.Web;
    var list = web.Lists[SourceList];
    var view = list.Views[ViewOfSourceList];

    var toolbar = new ViewToolBar();
    var context = SPContext.GetContext(
    Context, view.ID, list.ID, SPContext.Current.Web);
    toolbar.RenderContext = context;
    Controls.Add(toolbar);

    var viewHtml = new Literal {Text = view.RenderAsHtml()};
    Controls.Add(viewHtml);
  }

  protected override void Render(HtmlTextWriter writer) {
    EnsureChildControls();
    base.Render(writer);

    var web = SPContext.Current.Web;
    var list = web.Lists[SourceList];
    var view = list.Views[ViewOfSourceList];

    var items = list.GetItems(new SPQuery(view) {RowLimit = uint.MaxValue});
    foreach (SPItem item in items) {
      // Calculate total
    }

    // Render total and Javascript to replace 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:

  1. A ViewToolBar with the context of the list/view to be displayed
  2. A Literal containing the rendered HTML of the view to be displayed

This will then render as the original list/view.

On rendering the WebPart, get the items from the view, specifying the RowLimit 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:

public sealed class TextAggregatingWebPart : WebPart {
  protected override void CreateChildControls() {
    base.CreateChildControls();

    var web = SPContext.Current.Web;
    var list = web.Lists[SourceList];
    var view = list.Views[ViewOfSourceList];

    var toolbar = new ViewToolBar();
    var context = SPContext.GetContext(
    Context, view.ID, list.ID, SPContext.Current.Web);
    toolbar.RenderContext = context;
    Controls.Add(toolbar);

    var viewHtml = new Literal {Text = view.RenderAsHtml()};
    Controls.Add(viewHtml);
  }

  protected override void Render(HtmlTextWriter writer) {
    EnsureChildControls();
    base.Render(writer);

    var web = SPContext.Current.Web;
    var list = web.Lists[SourceList];
    var view = list.Views[ViewOfSourceList];

    var items = list.GetItems(new SPQuery(view) {RowLimit = uint.MaxValue});
    foreach (SPItem item in items) {
      // Calculate total
    }

    // Render total and Javascript to replace Count
  }
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文