Skip to Content
0
Former Member
Oct 03, 2016 at 01:35 AM

SAPUI5 - Get selected data from table

9167 Views

Hi Experts,

I am new in SAPUI5. I have a question and hope you could help. A sample code would be highly appreciated.

I created a table with selection indicator. And I'd like to know how to get selected data from this table by press button.

I used Batch Update button to trigger the event BatchUpdate to get selected data in this table.However I don't know how.

Here is my code for view.

<mvc:View controllerName="EMP_BATCH.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
  <Table  
  id="Employees" inset="false" 
  mode="MultiSelect"
  items="{ 
  path: '/EmpDetailsSet'  
  }"
     >
  <headerToolbar>
  <Toolbar>
  <Title text="Employee Info" level="H2"/>
  </Toolbar>
  </headerToolbar>
  <columns>
  <Column width="1em">
  <Text text="Emp Id"/>
  </Column>
  <Column width="1em">
  <Text text="Name"/>
  </Column>
  <Column width="1em">
  <Text text="Address"/>
  </Column>
  <Column width="1em">
  <Text text="Salary"/>
  </Column>
  <Column width="1em">
  <Text text="Street1"/>
  </Column>
  <Column width="1em">
  <Text text="Street2"/>
  </Column>
  <Column width="1em">
  <Text text="City"/>
  </Column>
  <Column width="1em">
  <Text text="Country"/>
  </Column>
  </columns>
  <items>
  <ColumnListItem>
  <cells>
  <Text text="{EmpId}"/>
  <Input id="Name" value="{Name}"/>
  <!--<Text text="{Name}"/>-->
  <Text text="{Address}"/>
  <Text text="{Salary}"/>
  <Text text="{Details/Street1}"/>
  <Text text="{Details/Street2}"/>
  <Text text="{Details/City}"/>
  <Text text="{Details/Country}"/>

  </cells>
  </ColumnListItem>
  </items>
  </Table>
    <Button text="Batch Create" press="BatchCreate" />
    <Button text="Batch Update" press="BatchUpdate" />
    <Button text="Batch Delete" press="BatchDelete" />
    <Button text="Refresh" press="Refresh" />
</mvc:View>

Here is the code of my controller.

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  'sap/ui/model/Filter',
  'sap/m/MessageToast'
], function(Controller,MessageToast,Filter) {
  "use strict";


  return Controller.extend("EMP_BATCH.controller.View1", {
  onInit : function () {
  // Get OData Model and set it to view
  var oModel = this.getOwnerComponent().getModel();
  var oView = this.getView();
  oView.setModel(oModel);
  },

  BatchUpdate: function(evt){
// Get selected data from table ??????

  }

  });


});

Hope any expert could help.

Thanks in advance. 😊