cancel
Showing results for 
Search instead for 
Did you mean: 

how to programmatically check the checkboxes in sap.ui.table based on some value?

Former Member
0 Kudos

hi,

I hav created a sap.ui.table with checkbox enabled.  On edit page, based on json value i need to check the checkboxes which are previously checked..How will i acheive this?

i want like this..

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Krishna,

This scenario would have been easier if you're using sap.m.Table. But since you're using sap.ui.Table and on top of it, you're using 'sapUiCozy' style for the view which makes requirement little complex. Check-boxes are visible due to 'sapUiCozy', otherwise they aren't. And these check-boxes cannot be accessed through normal methods.


You might need to consider writing the logic on formatter of the column where you want to differentiate row selected or not.

Here is a sample which is created based on sapui5 mock data and bound to 'ProductCollection': JS Bin - Collaborative JavaScript Debugging


Model used:

https://sapui5.hana.ondemand.com/sdk/test-resources/sap/ui/demokit/explored/products.json

Condition: When the supplier is 'Technocom', the row remains selected.


Regards,

Sai.

Former Member
0 Kudos

Hi sai,

Thanks:) Its works.. What i understood from ur code is whichever index is selected, that will be available in oTable._oSelection.aSelectedIndices array.. If we push values to this array then corresponding checkbox wil be sleected by default..

Answers (3)

Answers (3)

Former Member
0 Kudos

You can do that with expression binding.

Bind the 'selected' attribute of the checkbox control to an expression, like this:

selected="{= ${bonusType} === 'slow' }

Check here:

Expression Binding - User Interface Add-On for SAP NetWeaver - SAP Library

Former Member
0 Kudos

Hi Klause,

Sorry to jump in, what if I select 'medium' on create and that case too only 'slow' will be selected right? I think this hard coding will not work, right?

Best Regerds,

Namita

Former Member
0 Kudos

No, you have 3 checkboxes with 3 different expression bindings.

The data model must allow to present all 3 options for each data line.

Like this:

Checkbox 1:

selected="{= ${is_easy} === true }

Checkbox 2:

selected="{= ${is_medium} === true }

Checkbox 3:

selected="{= ${is_hard} === true }

Then you can have all possible combinations of those three.

Former Member
0 Kudos

Hi Krishna,

If I got you correctly - As the checkbox are in UI and there is no connection to DB while creating, you can't get which ones you selected while editing(if I am not wrong). The only way I can think of is, store the row indexs of selected boxs to somewhere while creating and then get them while editing and mark those indexs as checked...

Thanks and regards

Namita

Former Member
0 Kudos

Hi,

Can you explain this -"On edit page, based on json value i need to check the checkboxes which are previously checked." more?

Former Member
0 Kudos

in create page.. i will select some checkboxes and the corresponding value wil be saved in DB.. in edit page i wil get values from DB and show checkboxes previously selected.. how wil i achieve this?? lets say.. points:[{"bonusType":"slow"},{"bonusType":"medium"}]   is wat i get from DB then in UI i wil show slow and medium as checked and fast as unchecked