Forum Stats

  • 3,837,059 Users
  • 2,262,222 Discussions
  • 7,900,192 Comments

Discussions

Get row ID from af:table with javascript

3265832
3265832 Member Posts: 54
edited Mar 29, 2017 10:25AM in JDeveloper and ADF

Hello, I have a table that has client listener. When I select a row from a table it triggers the JS code. Now, I'd like to fetch either row ID or a value from a selected row. I have so far put the table as client component and fetched it with var textfield = AdfAgent.AGENT.getElementById('pt1:r1:1:pc1:t2'); . Now I would need a way to find out the ID of the caller row or to manipulate cell from called row.

jDev version 12.2.1.2.

With regards,

Darko

Answers

  • ScottHagen
    ScottHagen Member Posts: 17 Blue Ribbon
    edited Mar 28, 2017 12:08PM

    Hi, I've been trying to look into this and I think I've found a way to a partial solution to what you are looking for, at least for single selection.

    I've gotten the selected row keys and index of the selected row.

    Here is the javascript function, its a bit hacky in its implementation due to the seeming oddness of how the object returned by getSelectedRowKeys is

    function jsSelectionListener(evt){

        var source = evt.getSource(); // javascript representation of the ADF table

        var selectedKeys = source.getSelectedRowKeys()  // object that holds all of the selected row keys

        var selectedRowKey;

       

        // Got to iterate through the selected keys to find the actual selected key

        for(var i = 0; i < source.getRows(); i++){

            if(selectedKeys[i] !== undefined)

                selectedRowKey = i;

        }

       

        if(selectedRowKey !== undefined){

            console.log(source.getRowIndex(selectedRowKey) + " " + selectedRowKey); // shows two numbers, one for the row's index and another for the rowKey, they aren't necessarily the same number.

        }

    }

    Its called through a client listener through an af:table

    <af:clientListener type="selection" method="jsSelectionListener"/>

    This method only gets a number, rather than an ID or value, so it isn't quite what you were asking for.

    Here is docs I used if you'd like to look further.

    AdfSelectionEvent

    AdfRichTable

    Hope this helps.

  • managed BEAN
    managed BEAN Member Posts: 948 Silver Badge
    edited Mar 29, 2017 10:25AM

    Hello,

    If i understand correctly then take a look at the attached application and run it.

    You get a popup with dynamic client Id from button clicked in the table (the part of the path before the button id is the 'rownum' - that you want).

    Regards,

    Carlos

This discussion has been closed.