在视图导出中获取汇总计数? [英] Getting a summary count in a view export?

查看:22
本文介绍了在视图导出中获取汇总计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将视图导出到 excel.我已经在某处找到了一些代码,它在 xpages 中运行良好.现在用户想要添加总计的摘要.我会解释的.

I need to export a view to excel. I have already found some code somewhere and it is working great in xpages. Now the user wants to add a summary of totals. I will explain.

我有一个包含用户名、项目 ID 和设备 ID 的文档.我需要做的是导出具有特定项目ID的所有文档,在导出中显示用户名和设备ID,但在导出视图后,显示相似设备ID的汇总.

I have a document that contains a user name, project ID and Equipment ID. What I need to do is export all documents with a particular project ID, showing the user name and equpment id in the export but after the view is exported, show a summary total of the similar equipment IDs.

像这样:

       User              Selected Equipment
       Jonh Smith        C1
       Salley Johnson    C2
       Fred Days         C1


       Summary
       C1   2
       C2   1 

我想做的是首先在项目 ID 上使用分类视图,然后在设备 ID 上使用总和列,从 NotesViewEntryCollection 执行 getAllDocumentsByKey 以获取所选项目的所有文档,然后利用类别行获取我的需要的总数.但是当我只为 getAllDocumentsByKey 获取一个文档时.如果我删除设备列并仅按项目 ID 进行分类,那么我会得到所有预期的文档.

What I thought of doing is using a categorized view first on project ID then on Equipment ID with a sum column, do a getAllDocumentsByKey from a NotesViewEntryCollection to get all of the documents for the selected project then leverage the category line to get my needed totals. But when I do only get one document for the getAllDocumentsByKey. If I remove the Equipment column and only categorize on Project ID then I get all expected documents.

我的另一个想法是拥有一个可以存储在 sessionscope 变量中的对象,然后使用 getalldocumentsbykey 再次对项目 ID 进行排序.该对象将有一个设备 ID 变量和一个总数.当我通过视图工作时,我会更新当前设备 ID 的总数.然后在视图导出结束时导出这个 sessionscope 表.但由于我是 javascript 新手,我真的不知道从哪里开始.这是正确的方向吗?如果是这样,有人可以让我开始吗?

Another thought I had was to have an object that I could store in a sessionscope varible and just sort on project id once againn using getalldocumentsbykey. The object would have an equipment ID variable and a total. As I work though the view, I would update the total for the current equipment id. Then at the end of the export of the view jut export this sessionscope table. But since I am new to javascript, I really don't know where to get started on this. Is this the right direction? If so could someone get me started?

还有其他想法吗?

附言用户宁愿不必使用 Excel 的 Subtoal 功能.

P.S. The user would rather not have to use the Subtoal features of Excel.

推荐答案

Bruce,让您的生活更轻松并使用 ViewNavigator.ViewNavigator 具有类别条目,当您设置要汇总的值时,该值位于视图导航器中.它还具有从类别跳转到类别的方法,因此您可以读取更少的数据.例如,我使用此函数从分类视图(一级或二级)中获取汇总数据:

Bruce, make your live easier and use a ViewNavigator. The ViewNavigator has entries for the categories and when you set a value to be summed up that value is in the view navigator. It also has methods to jump from category to category, so you have less data to read. For example I use this function to get summary data from a categorized view (one or two levels):

function getCategoryData(viewName, dataColumn, getChildren) {
    var v = database.getView(viewName);
    var nav = v.createViewNav();
    var ve = nav.getFirst();
    var isFirst = true;
    var result = "[";
        while (ve) {
    if (!ve.isTotal()) {
        var curData = ve.getColumnValues();
        if (!isFirst) {
            result += ",";
        }
        result += "{label : \"";
        result += curData[0];
        result += "\", value : ";
        result += curData[dataColumn];
        /* for 2 level categories we fetch additional data */
        if (getChildren) {
            var childve = nav.getChild();
            var firstChild = true;
            result += ", children : [";
            while (childve) {
                var childData = childve.getColumnValues();
                if (!firstChild) {
                    result += ",";
                }
                result += "{label : \"";
                result += childData[1];
                result += "\", value : ";
                result += childData[dataColumn];
                result += "}";          
                firstChild = false;
                childve = nav.getNextSibling(childve);
            }
            result += "]"
        }
        result += "}";          
        isFirst = false;
    }       
    ve = nav.getNextSibling(ve);
}
result += "]";
return result;
 }

注意:它返回一个 JSON 字符串,而不是一个 JSON 对象.我需要字符串,所以你可能想改变它.您可以轻松修改函数以首先选择基于类别的子集:

Note: it returns a JSON String, not a JSON object. I needed the string, so you might want to alter that. You could easily amend the function to first select a category based subset:

function getCumulativeCategoryData(viewName, key, dataColumn, fetchChildren) {
var v = database.getView(viewName);

var nav = v.createViewNavFromCategory(key);
var ve = nav.getFirst();
    ...
 }

其中键是字符串或向量.您需要对数据类型小心一点.如果视图中的类别是数字,请确保使用 Number() 作为键,否则将不匹配.

Where key would be a String or a Vector. You need to be a little bit careful with data types. If a category in the view is a number make sure you use Number() for your key otherwise it won't match.

这篇关于在视图导出中获取汇总计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆