XPages ratio between 2 column totals in view

2019-08-01 21:25发布

I have a view with 2 columns. Both number types. I want to add a button to the page, which will calculate the ration between total of column 1 and total of column 2.

For example:
Column 1 | Column 2
5        | 5
10       | 10
4        | 3
3        | 4
It should be (5+10+4+3)/(5+10+3+4) = 1..

Thank you,

Florin

标签: view xpages
1条回答
地球回转人心会变
2楼-- · 2019-08-01 22:15

I would probably go into the view properties and turn on the totals for both those columns. Then in SSJS I'd get a NotesNavigator for that view and then create a NotesViewEntry object. Then I'd set that ViewEntry to the NotesNavigator.getLastEntry()... something like that. That entry should then have a columnValues() property. I THINK it would be something like:

var column1 = entry.getColumnValues()[1];
var column2 = entry.getColumnValues()[2];

Note: getColumnValues() is zero based and depending on the view design some columns might not be available to retrieve from getColumnValues().

Once you have you're 2 var's then you can do the math and do whatever with the result.

That's how I would approach it at least.

(I don't have an editor handy so sorry if some of the syntax is off)

查看更多
登录 后发表回答