Marcus Loza
Marcus Loza

Reputation: 185

Get page number on the xpages view panel

I need to catch the current page number of a view panel. I tried to grab for some property Pager component, but found none to return this value. Does anyone know how to get the value of the number of the current page.

I tried to apply the method indicated in the response of this post (Catching the Page Number), but clicking on a page in the pager of the error message The object does not support property or method 'addEventListenter' '

Upvotes: 1

Views: 435

Answers (2)

Knut Herrmann
Knut Herrmann

Reputation: 30960

I took your code and just changed it a bit so it shows names.nsf's view ($Users) so everyone can test it. It works.

I set different themes like "webstandard", "OneUI", "OneUI V3.0.2" and "Bootstrap3" - all work fine.

enter image description here

XPage:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:viewPanel rows="3" id="viewPanel1">
        <xp:this.facets>
            <xp:pager partialRefresh="true" layout="Previous Group Next"
                xp:key="headerPager" id="pager1">
            </xp:pager>
            <xc:ccPegaPagina xp:key="south" />
        </xp:this.facets>
        <xp:this.data>
            <xp:dominoView var="view1" databaseName="names.nsf"
                viewName="($Users)">
            </xp:dominoView>
        </xp:this.data>
        <xp:viewColumn columnName="FullName" id="viewColumn5">
            <xp:this.facets>
                <xp:viewColumnHeader value="Full name" xp:key="header"
                    id="viewColumnHeader5">
                </xp:viewColumnHeader>
            </xp:this.facets>
        </xp:viewColumn>
    </xp:viewPanel>
</xp:view>

Custom control "ccPegaPagina":

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:eventHandler event="onClientLoad" submit="false">
        <xp:this.script><![CDATA[ dojo.query('[id$=pager1] a').forEach(function(entry) {
                entry.addEventListener("click", function() {
                    alert(this.innerHTML);
                });
            });]]></xp:this.script>
    </xp:eventHandler>
</xp:view>

Put the code into a new database without any property changes and test it. If this works go from there.

Update

As we figured out in comments it doesn't work in IE 7 and 8.
The same applies for IE 11 with compatibility mode 7 and 8.
This is normal as addEventListener was first available in IE 9.
So, this solution needs at least IE 9 or any other modern browser.

Upvotes: 0

Marcus Loza
Marcus Loza

Reputation: 185

<!-- language: lang-js -->
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xc="http://www.ibm.com/xsp/custom">

    <xp:viewPanel
        rows="30"
        id="viewPanel1">
        <xp:this.facets>
            <xp:pager
                partialRefresh="true"
                layout="Previous Group Next"
                xp:key="headerPager"
                id="pager1">
            </xp:pager>
            <xc:ccPegaPagina xp:key="south" />
        </xp:this.facets>
        <xp:this.data>
            <xp:dominoView
                var="view1"
                databaseName="xxxx.nsf"
                viewName="vi_xxxx">
            </xp:dominoView>
        </xp:this.data>
        <xp:viewColumn
            columnName="nm_xxxx"
            id="viewColumn1">
            <xp:viewColumnHeader
                value="Nome xxxxx"
                id="viewColumnHeader1">
            </xp:viewColumnHeader>
        </xp:viewColumn>
        <xp:viewColumn
            columnName="Fonexxx"
            id="viewColumn2">
            <xp:viewColumnHeader
                value="Tel. xxx"
                id="viewColumnHeader2">
            </xp:viewColumnHeader>
        </xp:viewColumn>
        <xp:viewColumn
            columnName="celular xxx"
            id="viewColumn3">
            <xp:viewColumnHeader
                value="Celular particular xxx"
                id="viewColumnHeader3">
            </xp:viewColumnHeader>
        </xp:viewColumn>
        <xp:viewColumn
            columnName="FoneResidencial xxx"
            id="viewColumn4">
            <xp:viewColumnHeader
                value="Tel Residencial xxxx"
                id="viewColumnHeader4">
            </xp:viewColumnHeader>
        </xp:viewColumn>
    </xp:viewPanel>
</xp:view>

The custom control:

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

    <xp:eventHandler
        event="onClientLoad"
        submit="false">
        <xp:this.script><![CDATA[ dojo.query('[id$=pager1] a').forEach(function(entry) {
                entry.addEventListener("click", function() {
                    alert(this.innerHTML);
                });
            });]]></xp:this.script>
    </xp:eventHandler></xp:view>

Upvotes: 0

Related Questions