Skip to Content
author's profile photo Former Member
Former Member

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

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..

Capture.PNG (4.1 kB)
ca.PNG (4.8 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jul 19, 2016 at 12:47 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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..

  • author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 11:04 AM

    Hi,

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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 12:03 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 12:11 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.