on 2020 Jun 20 11:48 AM
Hello Team,
I am trying to enable "Edit button" by selection of a Table row, but it is not getting highlighted.error.jpg
Thanks & Regards,
Subrata Roy
Do it through a model property:
<Button id="EditButtonID" enabled="{yourLocalModel>/IsRowEditable}" >
You will probably want the Edit Button to be enabled only if ONE SINGLE row is selected, therefore, use the table's "rowSelectionChange" event, and the code would be like this:
onRowSelectionChange: function (oEvent) {
var oTable = oEvent.getSource();
var bIsRowEditable = !!(oTable.getSelectedIndices().length === 1);
this.getModel("yourLocalModel").setProperty("/IsRowEditable", bIsRowEditable);
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Artyom,
Thanks for your input.
I have tried the above functionality but it is not working.
Can you please guide me on this or provide me a sample application so that i can refer to.
::::Worklist.contrller.js(syntax):::
onInit: function () {
var oViewModel,
iOriginalBusyDelay,
oTable = this.byId("table");
oTable.attachSelectionChange(this.onRowSelectionChange, this);
onRowSelectionChange: function (oEvent) {
var oTable = oEvent.getSource();
var bIsRowEditable = !!(oTable.getSelectedIndices().length === 1);
this.getModel("worklistView").setProperty("/IsRowEditable", bIsRowEditable);
},
)
:::::::Worklist.view.xml(syntax):::
<Button icon="sap-icon://edit" enabled="{worklistView>/IsRowEditable}" id="test"></Button>
Artyom's reply works just fine.
Some small adjustments were needed on my side, but in general same functionality:
view.xml code, using sap.m
<core:View<br> xmlns:mvc="sap.ui.core.mvc"<br> xmlns:core="sap.ui.core"<br> xmlns="sap.m"<br> controllerName="yourAppPath.ext.controller.SensorAssignmentExt"><br><br><br><Table id="availableSensorsTable"<br> selectionChange=".onSelectionChange"<br><br>.........<br><br><br><FlexBox direction="Column" <br>alignItems="Start"<br> justifyContent="Center"><br> <Button enabled="{localSensorsDataModel>/IsAvailableSensorSelected}" <br>/><br>..........<br>
SensorAssignmentExt.controller.js code:
onSelectionChange: function (oEvent) {<br> const oView = this.getView()<br><br>const oAvailableSensorsTable = oView.byId('availableSensorsTable')<br> const bIsAvailableSensorSelected = !!(oAvailableSensorsTable.getSelectedItems().length > 0)<br> oView.getModel('localSensorsDataModel').setProperty('/IsAvailableSensorSelected', bIsAvailableSensorSelected) }
Before implementig all this, you need to have your local data model created, I do it during onInit like this:
var oView = this.getView()<br> if (!oView.getModel('localSensorsDataModel')) {<br> var olocalSensorsDataModel = new JSONModel(<br>{ aSensors: [],<br> IsAvailableSensorSelected: false, })<br><br>oView.setModel(olocalSensorsDataModel, 'localSensorsDataModel')<br> }
Thanks for the solution!
Regards!
PS: Using the "code" option for pasting some source code is nightmare.....
User | Count |
---|---|
71 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.