Problem with multiple delete with CTRL+A in table in ADF

Scenario: When we do a CTRL+A to select all record in table in ADF and perform delete action, It will not delete all the record in table. Only some of record will get deleted and some left undelete in table.

To delete the record programatically usually we write code like this:

RowKeySet rowKeySet = getTableName().getSelectedRowKeys();
        CollectionModel cm = (CollectionModel)getTableName().getValue();
        for (Object facesTreeRowKey : rowKeySet) {
            tableName.setRowKey(facesTreeRowKey);
            JUCtrlHierNodeBinding rowData =
                (JUCtrlHierNodeBinding)cm.getRowData();
            if (rowData != null) {
                    rowData.getRow().remove();
                }
        }

But this piece of code will work fine in case of 2-3 record but not in case of CTRL+A.

So in order to make it work for deleting all the record using CTRL+A we have to modify the code as follows:

    RowKeySet rowKeySet = getTableName().getSelectedRowKeys();
        CollectionModel cm = (CollectionModel)getTableName().getValue();
        Object[] rowKeySetArray = rowKeySet.toArray();
        for (Object facesTreeRowKey : rowKeySetArray) {
            tableName.setRowKey(facesTreeRowKey);
            JUCtrlHierNodeBinding rowData =
                (JUCtrlHierNodeBinding)cm.getRowData();
            if (rowData != null) {
                    rowData.getRow().remove();
                }
        }

The above code will perfectly work in case of multiple delete in ADF table.

Happy coding :)

Comments

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli