1
votes

I need to mark check boxes in view control based on selection of combo box value.

For example, I have a view of Customer Order documents and I need to select all of the orders that are "Pending". The end user could scroll down the screen and check mark each row that has a status of "Pending", but there may be 50 scattered throughout the view. I would like to have a combo box where the end user could select "Pending" and XPages would check mark all the matching documents for them. Then I have a button that would use .getSelectedIds() to act on those documents.

I have tried using rowData.setSelected(true), but this does not show a check mark in the viewColumn for the row.

Is there a way to access the XPage default checkbox in the viewPanel.

2

2 Answers

1
votes

I'm not a big fan of the View Control. I'm sure what you describe can be done but I'll offer an alternative approach.

I did this video showing a way to kinda of do a getSelectedIDs() from a repeat control (don't use IE): http://xpages.tv/xtv3.nsf/episode_user.xsp?action=openDocument&documentId=94A

In that example the user could click on a row and I would add that ID to a map in sessionScope I think. Maybe viewScope - I forget. I used CSS to highlight the row to show it was selected. There was a button that removed the id from the map and refreshed to remove the highlight.

Now what you want to do - let's forget checkboxes for now. You should be able to use this repeat control technique then above your repeat have a button like Select all Pending. That button would run a SSJS function that would loop through your data on the backend and get the correct UNIDS and then add them to the map. A Partial refresh of the repeat would show them all selected. Another button that needs to act on the selected list would then just reference that map of the ID's.

Where I used css to highlight the row I imagine you could have a checkbox control and of that particular row was in the map - add the check, otherwise leave it empty.

Anyway - that's one way to approach it that you should be able to get working on short order.

Really if you're using a view control I guess you could still have a button that got the documents via the backend and do similar processing. In that case you might not need to add that check the the view since the selection is hard coded in reality. I guess the question is if you still need to mark them if you have that hard coded button.

1
votes

Using some tidbits from David Leedy's response I was able to create a solution by keeping a collection of selected UNID's in a scope variable, using a java.util.ArrayList()

// in the postOpenView of the custom control I put...
if (sessionScope.myList==null) {
    var myList = new java.util.ArrayList();
    sessionScope.put('myList',myList);
}

// in the onchange event of my combobox I put the following code,
// and set the partial update to viewPanel1
var myArray = sessionScope.get("myList");
var keycode;
var vp:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1");

for(i=0; i < vp.getRowCount() ; i++){

    vp.setRowIndex(i);
    var rowData=vp.getRowData();

    keycode = rowData.getUniversalID();

    //my combobox is bound to the sessionScope viewFilter
    var test1 = sessionScope.get("viewFilter")==" "; //(used for select all)
    var test2 = rowData.getColumnValue("$3").toString().startsWith(sessionScope.get("viewFilter"));

    if (test2 || test1) {

        if (!myArray.contains(keycode)) {
            myArray.add(keycode);
        }

    } else {
        myArray.remove(keycode);
    }
}  

I also added a column to the view with a faux checkbox (which is just cosmetic) where I can select additional rows to add (or remove) from "myArray"

// the onclick event of my faux checkbox column
// with partial update set to viewPanel1 

var myArray = sessionScope.get("myList");
var keycode = rowData.getUniversalID();

if (!myArray.contains(keycode)) {
    myArray.add(keycode);
} else {
    myArray.remove(keycode);
} 

Thanks for all the help!