Count entries in XPages view - xpages

My XPage has a view data source with a search formula ("Search in view results") constructed from URL parameters.
The search results are displayed in a repeat control that sits inside a panel. I want to hide this panel if there are no search results and display an appropriate message instead.
The panel is visible based on the following code:
var vec:NotesViewEntryCollection = view1.getAllEntries();
vec.getCount() != 0;
However it seems that getAllEntries returns all entries in the view before the filtering takes place. The Help for AllEntries says "If a view is filtered by FTSearch, this property returns the entries in the filtered view."
Have I misunderstood this? Is there a way that I can get the number of entries AFTER the filtering has taken place?

When you're accessing the dominoView datasource via SSJS you're not getting the dominoView but the NotesView associated with it. That's why the properties and methods available are for the NotesView class. But the search is being performed on the dominoView datasource front-end not on the NotesView object associated with it.
Instead of using the datasource, get the control that uses it (e.g. A repeat, viewPanel etc) and use the getRowCount() method. This will give you the right total. E.g.
getComponent("repeat1").getRowCount()

Using the View caption property....
sample: "Displaying 30 of 30220"
<xp:this.caption><![CDATA[#{javascript:return "Displaying " + getComponent("viewPanel1").getRowCount() + " of " + view1.getAllEntries().getCount();}]]></xp:this.caption>
NOTE: This counts the categorized row as well.

Related

xpages categorized column

A lotus notes application is using a view with a column which is not categorized but is having the Show twsitie when row is expandalbe property check and it also is listing some documents.
Column formula:
#If (Form = "fmProiect";
"P: " + txt_Proiect;
Form = "fmDocCRM";
txt_Subiect;
"" )
I'm trying to achieve the same thing in a view panel - having the above view as Data Source Domino View.
I tried to add some icons for the expand/collapse property:
<xp:viewColumn columnName="$6" id="viewColumn3"
collapsedImage="/2.png" expandedImage="/1.png">
But still the column isn't categorized. Is there a way I can achieve this?
Add the attribute indentResponses="true" to your xp:viewColumn. Then response documents can by collapsed and expanded.
Note: As you described in your question, you have in Notes Client view the column not categorized but you can make visible or hide documents behind a document in view. Those documents are "response documents". They have an internal item "$REF" with the document id of the parent.

checking if current user is author of the document

I have a formA where I have a field '_author' which is of type Authors/Computed for display with value (#Subset($Updatedby;1)). I display information from formA on viewA. What I want to achieve is that documents that are created by you are only visible to yourself on viewA. I tried the following formula in viewA 'View Selection':
SELECT (form = "formA" & #UserName =_author). Even though I know that these two variables have the same values when I read it from the document's properties, the condition is not satisfied and I do not see a single document. If I delete everything after "&", the view shows all documents.
All is hosted on a server which handles users.
A handy workaround is to create a Page with an embedded view. This view is exactly like your view but has an additional first categorized (!) column with your field _author.
Put into embedded view's property "Show single category" the formula #UserName or #Name([CN]; #UserName) depending on how your categorized column _author is formatted. Show then always the Page instead of the view.
This way you avoid trouble with "Shared, private on first use" views and users see exactly their own documents only.
#UserName works in a special manner in selection formulas in views. In your case the view should be Private on First Use. Read further here: http://www-01.ibm.com/support/docview.wss?uid=swg21089773 .
Be aware that this lead to all sort of issues, e.g. when you update the design of the view users must remove the view manually to get the changes deployed.

Getting data from a datasource with Filter by Column Value?

I have a list box where I am trying to get the datafrom the people view in names.nsf.
The first column of the people view is computed and shows Last Name , First Name.
The code below works fine for my list box values but it does not take into consideration the value in the Filter By Column Value. Basiclly the code below acts like the Filter By Column value property does not exist. I know the Filter by Column value property is working because I replaced a repeat control on the page with a computed field and the repeat control is displaying the value excepected but the list box is displaying values from the first document in the view.
Thoughts I had to fix this are:
Use getAllDocumentsByKey to just search the people view but when I do that I lose the column values and I would need to recompute the value, something that I would like to avoid if possible incase the column formula changes.
Use FTSearch but what I really need to do is search that first column only and I am not aware of search operator that searchs a column only. Is there such a thing?
Another thought would be to somehow use the values of a repeat control, as the values for my list box, but I am guessing that this is not possible. I sort of thinking something with a scope varibale but I have not worked that out yet.
A repeat control works. How can I get my code to loop through the doeuments the same way a repeat control does?
And as a side question, is there anyway to tie a pager to a datasource as oppsed to a repeat control.
BTW What I currently do is to build a list box using a few computed fields and a repeat control but what I really want to do is to use a regular xpages list box control.
Here is the code:
var doc:NotesDocument = view1.getFirstDocument();
while (doc != null && count<10)
{
var tmpDoc:NotesDocument = view1.getNextDocument(doc)
ret.push(doc.getColumnValues()[1]);
doc.recycle();
count++;
doc = tmpDoc;
}
Try to use getAllEntriesByKey. This will give You access to column values (through ColumnValue property of view entry).

How to prevent a viewPanel with category filter showing empty rows if filter is not set

I'm having this categorized view displayed in a view panel where the category column itself is not shown. Instead I'm displaying a combobox above the viewPanel where users can select from all the categories available (see screenshot below). The combo is bound to a scopeVariable and is refreshing the viewPanel onChange. The viewPanel has a computed categoryFilter reading from the same scopeVar. That all works nicely.
Now I also have implemented an additional wildcard (*) value in the selection list which (if selected) programmatically sets the cat filter to NULL. This way I'm forcing the viewPanel to show all entries. Again, this works fine, but with the drawback that now the view is showing empty rows where the category entries would be shown normally (in the screenshot you see empty rows above each entry, with 2 entries for the category "edcom GmbH" obviously belonging to the same category; those aren't separated by an empty row):
One way to at least hide those empty rows would be through means of css coding. But I would prefer those rows not being rendered at all.
Can this be done at all using a viewPanel, and how? Or do I have to use other controls like a repeat or a dataTable maybe?
Thanks in advance,
Lothar
One "hack" (an ugly one I admit) would be to change your categorization column from Firma to Firma:"--All--" or Firma:"*" and then instead of setting the category filter to NULL you set it to "--All--" (or "*").
The double category hits the indexer, but should do what you need.
Obviously there's no easy way. So meanwhile I'll stick to this css-style solution:
In the view panel und All Properties - data I set var = "entry". Then, under All Properties - styling I set a programatic value for the rowClasses property:
if(entry.isCategory()){
return "rowStyleHidden";
}
return "";
The style class "rowStyleHidden" hides those rows using
display: none;
Don't know yet how this turns out performance-wise, I'll have to observe this once I implement it in a copy of the real database.
You can also switch to a none categorized view, by having the viewname calculated based on the value in combobox.

jqGrid Filtering Records

It seems there have been a few questions here regarding this subject, and they have some great answers, but it seems that my case is a little different. I need to filter the records displayed in a jqGrid, but entirely client-side.
For a number of reasons, the best way for me to populate my grid is with an array that's emitted directly into the JavaScript on the page. The grid itself doesn't interact with the server at all. I have some custom AJAX happening in various grid events, but that's it. (Basically, I'm integrating this with an existing set of available services which can't change significantly.)
What I'm looking to do is filter the grid based on a simple text input and button. My page has the text input, the button, and a table (which becomes the grid on document ready). I'd like to bind to the click event of the button (normal jQuery event binding, nothing special) and use the value from the text input as a display filter on the jqGrid.
By "filter" I mean to display only the records which contain a match (in any field) for the text in the input. Then, to display all records, just empty the input and click the button again. Additionally, the grid is multi-select and the selections need to persist through filtering. I just need to be able to hide the rows which don't match what's in the input.
Is this possible?
To filter local grid you should only fill filters property of the postData parameter of jqGrid and set additionally search:true.
To save selection of the grid you can use reloadGrid with additional parameter [{page:1,current:true}] (see here).
The corresponding code can be the following
$("#search").click(function() {
var searchFiler = $("#filter").val(), grid = $("#list"), f;
if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData,{filters:""});
}
f = {groupOp:"OR",rules:[]};
f.rules.push({field:"name",op:"cn",data:searchFiler});
f.rules.push({field:"note",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
grid.trigger("reloadGrid",[{page:1,current:true}]);
});
I made the demo for you which filter for two columns 'Client' ('name') and 'Notes' ('note') you can extend the code to search in all columns which you need.
Depend on what you exactly mean with the saving row selection you can need to save the current selection from the selarrrow in a variable and restore the selected rows with respect of setSelection method.

Resources