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

getting data from table

Hi everyone,

I've created a table and I've given a link on the primary key of my table so that when i click on that link it should show me the data related to that id.

so can anyone help me with the proper code to get the data on the click of the link.

Thanks

Anshul D

image_N3.PNG (3.6 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 29, 2014 at 08:02 AM

    Hi Anshul,

    Please refer the following code:

    First you have to create an function to be called when we click on the link:

    new sap.ui.commons.Link({press: oController.linkPress}).bindProperty("text", "matnr");

    in the controller page under the function link press you can get the id of the item pressed using the following code:

    var str = oControlEvent.getParameters().id;

    var n = str.lastIndexOf("row");

    var res = str.substr(n+3);

    var i = parseInt(res);

    overlay = sap.ui.getCore().byId("overlay");

    var oTable = sap.ui.getCore().byId("table");

    var matty = oTable.getRows()[i].getCells()[7].mProperties.value;

    var plant = oTable.getRows()[i].getCells()[5].mProperties.value;

    var matnr = oTable.getRows()[i].getCells()[1].mProperties.text;

    Thanks and Regards,

    Ashish

    Add a comment
    10|10000 characters needed characters exceeded

    • It really really really is a bad idea to reference view objects (overlays, tables, cells, etc) from the controller, since it violates the MVC principle!

      A much better approach would be to simply have the following in your link press handler:

      onLinkPress: function(oEvent) {

      var obj = oEvent.getSource().getBindingContext().getObject();

      var empName = obj.Empname;

      var mandt = obj.Mandt;

      // etc

      }

      this will get the current object (i.e. The selected object in your table) of the binding context, whether it's visible in your table or not (which is another benefit)

  • Posted on Jul 28, 2014 at 01:57 PM

    Hi Anshul,

    You mentioned "I've created a table and I've given a link on the primary key of my table......" so just post your code so that it will be useful to guide you.

    Regards,

    Madhumahesh.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member
      <items> <!-- Column List -->
             <ColumnListItem>
              <cells id="data">
              <Link press="display" id="link" text="{Mandt}"/>          
      
      
                <Text
                  text="{Empid}" />
                <Text
                  text="{Empname}" />
                <Text
                  text="{Mandt}" />
                <Text
                  text="{Empid}" />  
                <Text 
                  text="{Empname}" />
                <Text 
                  text="{Empname}" /> 
                  <Text
                  text="{Empname}"/>             
              </cells>
            </ColumnListItem>
           </items> 
      

      Hi Madhumahesh,

      I am calling all this data from the table and for first Mandt i have given a link with the function display so on pressing this link i should get the data of all the fields. So i need the code or help to how to get the data.

      Thanks,

      Anshul D

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.