Skip to Content
avatar image
Former Member

How to add colors to new sap.m.Button

Hi Guy's,

//IF my status is "B" "BUY" Button should be green if my status is "Q" my  "QUOTE" should be Blue.                    

venderdata: function(sKey) {
var a = this.getView().byId("quantity");
var that = this;
var oTable = this.byId("idTblVendor");
var url = "/VendorData('" + sKey + "')/Results";
var itemTemplate = new sap.m.ColumnListItem({
	cells: [
		new sap.m.Text({
			text: "{VENDOR_NO}"
		}),
		new sap.m.Text({
			text: "{VENDOR_NAME}"
		}),
		new sap.m.Text({
			text: "{PRICE}"
		}),
		new sap.m.Button({
			text: "Quote",
			// type: "Emphasized",
		}),
		new sap.m.Button({
			text: "Buy",
			// type:"Accept",
		}),
		new sap.m.Text({
			text: "{STATUS}"
		})
	]
});
oTable.bindItems({
	path: url,
	template: itemTemplate
});
},

capture444.jpg (16.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    May 18 at 03:56 PM

    use expression binding for button type

    var itemTemplate = new sap.m.ColumnListItem({
    	cells: [
    		new sap.m.Text({
    			text: "{VENDOR_NO}"
    		}),
    		new sap.m.Text({
    			text: "{VENDOR_NAME}"
    		}),
    		new sap.m.Text({
    			text: "{PRICE}"
    		}),
    		new sap.m.Button({
    			text: "Quote",
    			type: "{= ${STATUS} == 'Q' ? 'Accept' : 'Default' }"     //expression binding
    		}),
    		new sap.m.Button({
    			text: "Buy",
    			type: "{= ${STATUS} == 'B' ? 'Accept' : 'Default' }"      //expression binding
    		}),
    		new sap.m.Text({
    			text: "{STATUS}"
    		})
    	]
    });
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you Srikanth KV your answer helpful for me .

      small change

      type:"{= ${STATUS} === 'B' ? 'Accept' : 'Default' }" //expression binding

  • May 18 at 03:46 PM

    options are to enhance the main model with a value emphasised ir accept before binding it to control for the property Type.

    Else use a separate model and fir each row set accept or emphasised .

    Add comment
    10|10000 characters needed characters exceeded