Data View with a NotesViewEntryCollection
Jan 20, 2015
http://www.bleedyellow.com/blogs/DominoHerald/entry/data_view_with_a_notesviewentrycollection?lang=en_us


So I've been wanting to use a Date View for a while, but I've not had the time I need to sit down and puzzle it out. And (soap box here) the examples given are pretty complex. I do have a sample based on Brad's work that I will be posting. But as I get that together, here is a tidbit.
When you use a Data View, you are only given the option of selecting a Domino View. I wanted to see if you could do it with a collection. It turns out you can. What I did was this (in my odd discovery process) I created a DataTable based on a NotesViewEntryCollection of all entries in a view. I copied the <xp:this.value>  node from it and replaced the <xp:this.data><xp:dominoView ...> nodes in the dataView. And the page renders. I've only put a pager in to see if it's got full functionality, and that's working, so I suspect that various other things will as well.
Here is the entire XPage. It should work for you just changing the view name and the field you get. Plus, it's a start to using the Data View if you've not started yet :)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="
http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">

    <xe:dataView
        id="dataView1"
        var="rowData"><xp:this.facets>
    <xp:pager
        layout="Previous Group Next"
        partialRefresh="true"
        id="pager1"
        xp:key="pagerTopLeft">
    </xp:pager></xp:this.facets>
        <xp:this.value><![CDATA[#{
javascript:var nView:NotesView=database.getView('Name');
var nVEC:NotesViewEntryCollection=nView.getAllEntries();
return nVEC;}]]></xp:this.value>
        <xe:this.summaryColumn>
            <xe:viewSummaryColumn value="#{
javascript:rowData.getDocument().getItemValueString('Subject');}"></xe:viewSummaryColumn>
        </xe:this.summaryColumn>
    </xe:dataView></xp:view>

 
Cheers,
Brian
 

 

Add a Comment 
Edit 
More Actions 
Comments (4)


1 Brad R Balassaitis commented Jan 21 Permalink Recommendations 0
Great tip! I've used this with arrays of JavaScript objects as well (as a way to minimize overhead when refreshing). The Data View is an incredibly flexible control.


2 Brian M Moore commented Jan 21 Permalink Recommendations 0
@Brad - Thanks Dude! I'm a fan of yours - and so it's an honour to see you commenting here.

 


Can/will you post an example of using JS Objects? Like so much of what you do, I'd like to adopt it.


3 Brad R Balassaitis commented Feb 1 Permalink Recommendations 0
Below is a working example (it looks like it's stripping out the reference to the SSJS script library, but I think everything else is in tact).

 


Basically, I set up a script library function to walk a view and build an array of objects with data to display. The data view page includes the script library and gets the data by setting the "var" property to: return getData(); (there's no "data" property to set, because it's not using a view data source). Each data object has a Name, City, and Country property. I set the Name as the summary column and the other two as extra columns.
 
I've used this in combination with a scope variable to check whether I should re-build the data or just leave it as is, so it's not refreshing as much. I don't have benchmarks on it, but it makes sense to me conceptually.
 
[Data View XPage]
 
 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
 
<xp:this.resources>
 
</xp:this.resources>
 
<xe:dataView id="dataView1" var="dvRow" value="#{javascript:return getData();}">
 
<xe:this.summaryColumn> 
<xe:viewSummaryColumn value="#{
javascript:return dvRow.Name;}"> 
</xe:viewSummaryColumn> 
</xe:this.summaryColumn>

 
<xe:this.extraColumns> 
<xe:viewExtraColumn value="#{
javascript:return dvRow.City;}" columnTitle="City"> 
</xe:viewExtraColumn> 
<xe:viewExtraColumn columnTitle="Country" value="#{
javascript:return dvRow.Country;}"> 
</xe:viewExtraColumn> 
</xe:this.extraColumns>

 
</xe:dataView>
 
</xp:view>
 
[Script Library Function]
 
function getData() {
 
var data = [];
 
var vw:NotesView = database.getView('ByName-First'); 
var nav:NotesViewNavigator = vw.createViewNav(); 
var ve:NotesViewEntry = nav.getFirst(); 
while (ve != null) { 
var columnValues = ve.getColumnValues();

 
var thisRow = {}; 
thisRow.Name = columnValues.elementAt(0) + ' ' + columnValues.elementAt(1); 
thisRow.City = columnValues.elementAt(3); 
thisRow.Country = columnValues.elementAt(6); 
data.push(thisRow);

 
var tmpentry = nav.getNext(); 
ve.recycle(); 
ve = tmpentry; 
}

 
return data; 
}


4 Brian A Moore commented Feb 1 Permalink Recommendations 0
That's amazing! Thanks!
This is an archive of my previous blog http://www.bleedyellow.com/blogs/DominoHerald attachments are in the download control