cancel
Showing results for 
Search instead for 
Did you mean: 

Hide delete button for certain rows in table

florian19982
Explorer
0 Kudos
2,385

Dear fellow Sappies,

I am new SAPUI5 and I was not able to find a solution to a problem that should not be that difficult.

My database table looks something like this:

TestTable
firstName  | secondName  | protected
-----------|-------------|----------
John       | Doe         | X
Chris      | Parker      |

Now, I want to display this table (the first two columns) in a sap.m.Table.

The table should be in "delete" mode, so that I can delete all columns that are not protected.

In my view, I defined a table like this:

<Table mode="Delete" delete="_onTableDelete" id="testtable" items="{/TestSet}">
    <columns>
        <Column>
            <header>
                <Text text="First Name"/>
            </header>
            <footer/>
        </Column>
        <Column>
            <header>
                <Text text="Second Name"/>
            </header>
            <footer/>
        </Column>
    </columns>
    <items>
        <ColumnListItem type="Active">
            <cells>
                <Text text="{firstName}"/>
                <Text text="{secondName}"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

How can I achieve that the delete button at the end of each row is only shown if the "protected" attribute is false?

Thank you very much for your help!

View Entire Topic
agrawalaadhar8
Participant

Hi,

Though using a custom button as suggested above can work.

Here is how you can remove the delete button.

Use the updateFinished event handle of the table.

Inside that you can loop in the rows of the table, and for the row which has protected 'X' you can set the button visibility false.

Try if this works.

Regards

var rowCount = oTable.getItems().length;
for( rowIterator = 0; rowIterator < rowCount; rowIterator++ ){
  var row = oTable.getItems()[rowIterator];
  var protected = false;
  //**Writre Logic here to get the "proctected" value for the current row  
  if(protected){
    row.getDeleteControl().setVisible(false);
  }
}
florian19982
Explorer
0 Kudos

That worked!

Thanks a lot!