poorv chauhan
poorv chauhan

Reputation: 19

Number of selected documents in Xpages using CSJS

I have view panel in my xpages which shows checkbox against each document, now I would like to know how many documents are being selected by user in csjs so I can confirm with user on how many documents are being deleted and same would be part of alert message ( ex, you have selected 10 documents are you want to proceed? )

and then once confirmation is done I will proceed with SSJS to delete them.

Thanks Man

Upvotes: 1

Views: 205

Answers (2)

Dominik Myszkowski
Dominik Myszkowski

Reputation: 302

If You just want to count them, then You can use the CSS selector which is beign distributed to view checkboxes by default (unless You changed it explicitly):

function getSelectedCount() {
    var checkboxes = dojo.query(".xspCheckBoxViewColumn");
    var selectedCount = 0;
    for (var i = 0; i < checkboxes.length; i++) {
        //check if it is selected
        if (checkboxes[i].checked) selectedCount++;
    }
    return selectedCount;
}

If You need the documents Note IDs, then the elements returned by this query have a "value" property with NoteID:

dojo.query(".xspCheckBoxViewColumn")[0].value // NoteID of first selected element

If You need the array of selected IDs:

function getSelectedIds() {
    var checkboxes = dojo.query(".xspCheckBoxViewColumn");
    var selectedIds = new Array();
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) selectedIds = checkboxes[i].value;
    }
    return selectedIds ;
}

Upvotes: 1

Bob Yesenskiy
Bob Yesenskiy

Reputation: 414

I do something similar but all in ssjs. sessionScope variable store the Note ID which when selected. The count is display on a panel. You use a dialog box to confirm the documents to delete. Code example:

        <xp:viewColumn
            id="viewColumn1"
            value="">
            <xp:checkBox
                text=""
                id="checkBox1">
                <xp:this.readonly><![CDATA[#{javascript:var v = rowData.getColumnValue("ChkInDate");
v == ""?false:true;}]]></xp:this.readonly>
                <xp:eventHandler
                    event="onclick"
                    submit="true"
                    refreshMode="partial"
                    refreshId="panelAction">
                    <xp:this.action><![CDATA[#{javascript:var rv = rowData.getNoteID();
var vector:java.util.Vector = sessionScope.get("Selected");
var idx = vector.indexOf(rv);
if(idx == -1){
    vector.addElement(rv);
}else{
    vector.removeElementAt(idx)
}
}]]></xp:this.action>
                </xp:eventHandler>
            </xp:checkBox>
            <xp:this.facets>
                <xp:viewColumnHeader
                    xp:key="header"
                    id="viewColumnHeader1"
                    style="text-align:center"
                    value="Select">
                </xp:viewColumnHeader>
            </xp:this.facets>
        </xp:viewColumn>

Upvotes: 0

Related Questions