1
votes

I'm working on an Xpages application on which I have a view control. I tried to put a checkbox in the column header to select all of the check boxes in the view. The problem is when I go to another page from the view, its lines are not checked and the selection is made only on the visible page. So, I want to be able to select all the rows in all the pages of the view, this without the selection disappears when switching from one page to another of the view.

1
I am not sure if this is going to be possible with a traditional view control. You could accomplish this with a repeat control having each check box save a value.Patrick Sawyer
Have a look at this for inspiration too: hasselba.ch/blog/?p=1062Per Henrik Lausten
As you can see from the answer and the other comments this is not a really simple task. My main question however is what you want to do with all the selected entries? Most of the times there are other ways to accomplish a goal. Or in other words: coming from Notes client development and moving to Xpages we naturally tend to look for similar solutions like the ones we always used. Which quite often aren't the best onesLothar Mueller

1 Answers

2
votes

There are couple of problems with views and selections.

First of all, pager actions to move between pages does not process 'select all rows' data because it is enabled to use partial execution by default. If you put partialExecute="false" into your pager, you will see that 'select all rows' checkbox will be maintained between pages.

However, if you have a checkbox on a column and the columnHeader, the component maintains a selectedIds array in the back-end. Unfortunately, this array holds only visible selections. Because the array is maintained by the viewPanel component, which is not aware of the list of data entries that are not shown.

Also, checkbox implementation does not provide any even mechanism where you can grab selections on the back-end to cache them between pages.

To determine select all checkbox can be doable with a little trick. Assuming you are using all default styles;

<xp:inputHidden
    id="inputAllSelected"
    value="#{viewScope.allSelected}"
    defaultValue="false"></xp:inputHidden>
<xp:scriptBlock
    id="scriptBlock1">
    <xp:this.value><![CDATA[
function getSelectAllCheckbox() {
    return dojo.query("input.xspCheckBoxViewColumnHeader")[0];
}

function toggleSelectAll(){
    dojo.byId("#{id:inputAllSelected}").value=getSelectAllCheckbox().checked;
}

dojo.addOnLoad(function() { 
    dojo.connect(getSelectAllCheckbox(), "onchange", toggleSelectAll);
});
]]></xp:this.value>
</xp:scriptBlock>

To cache checkboxes between pages, you would implement your own checkboxes by using custom columns. I recommend using a data table component to get more flexibility.