Skip to Content
avatar image
-1
Former Member

SAP UI5 how select a table row and get data?

Hallo!

I made this table and would like to get information from selected row. How can I select row and get information?

And how can I improve table style?

Thank you in advance!

unbenannt.png (70.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Oct 25, 2016 at 12:11 AM

    Hi Khristina,

    Will this sample help? Table

    Regarding the table style, what do you like to do? You want to add some border-design / colors etc?

    Regards,

    Sai.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 26, 2016 at 10:55 AM

    Thank you for your answers. But unfortunately it's not working.

    var rowid = tb.getSelectedIndices(); The programm says that getSelectedIndices() is not defined. Could you please me also say how can I set a value? I would like to get something like this when I choose a row.

    Status: Anzahl Anteil%

    Offen 6 66%

    I wrote like this and it works...but I don't know how to set a value

        onSelectionChange: function(oEvent) {
             
                var oSelectedItem = oEvent.getParameter("listItem");
                var s1pt = oSelectedItem.getBindingContext().getProperty("Status02Perc");
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 25, 2016 at 01:11 AM
    -1

    Hi,

    You can use the following function to get the selected row, then get the value from a specific column:

    var tb = this.getView().byId("table");

    var rowid = tb.getSelectedIndices();

    var kosten = tb.getRows()[rowid].getCells()[0].getText();

    var object = tb.getRows()[rowid].getCells()[1].getText();

    Regards,

    Michael

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 02, 2016 at 11:42 PM

    I am not sure what you try to do ... but I am exptecting the following

    you have a table with information. You click on a line and you want to see that information displayed now in a form for example. Only that one line information you have selected in the table before. and you used sap.m.table for the table

    Therefore you can reach this with the following .. by using a Dialog Fragment to display the detail information and bind the context of the selected line to the context of the form in the dialog fragment

    in your controller

    closeDialog: function()

    { this._getDialog().close(); this._oDialog.destroy(); this._oDialog = false;

    },

    onExit: function()

    { if (this._oDialog) { this._oDialog.destroy(); }

    },

    onSelectionChange: function(oEvent){

    this._getDialog().open();

    },

    _getDialog: function(){

    //check if dialog is not open at all

    if (!this._oDialog) {

    var oTable = this.byId("yourTableId");

    this._oDialog = sap.ui.xmlfragment("namespace.fragmentName", this.getView().getController());

    this.getView().addDependent(this._oDialog);

    var sSelectedContext = this.getSelectedContexts().toString()

    //binding fragment form to SelecteContext of Table

    sap.ui.getCore().byId("idoftheForminFragment").bindElement(sSelectedContext);

    }

    return this._oDialog;

    }

    Add comment
    10|10000 characters needed characters exceeded