Skip to Content

Dynamic binding for sap.m.switch in a sap.m.Table

I have a requirement where we need to show data in sap.m.Table where columns are Question and Ans.

For objective type question the Ans column should have a sap.m.switch instead of a free text.

I am able to do up to this.

However I am having issue in binding the state of the sap.m.switch control.

My table definition is:

<Table id="idQATable1"



path: '/QA',

sorter: {

path: 'QuestionType'}








<ColumnListItem >


<Text text="{Question}" />

<Switch state="{Ans==true}" customTextOn="Yes" customTextOff="No"/>





The issue is the data type on the table for "Ans" is String but Switch state is a boolean value. I tried with putting condition check directly in the binding

state="{Ans==true}". But this is always returning false. so the switch is showing in false state always.

Please help on how to put such conditions within table column?



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 10, 2015 at 11:37 AM

    Found a solution. So thought of sharing:

    resolved this using formatter funtion:

    Control declaration in my XML view:

    <Switch id="ansYN" state="{ path: 'Ans', type: 'sap.ui.model.type.String', formatter: 'getBooleanValue' }" customTextOn="Yes" customTextOff="No"/>

    And my formatter funtion:

    getBooleanValue : function(Ans){

    var boolAns = new sap.ui.model.type.Boolean();

    if(Ans === "true"){

    boolAns = true;


    boolAns = false;


    return boolAns;


    Add a comment
    10|10000 characters needed characters exceeded

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.