Search code examples
javascriptpentahodashboardpentaho-cde

Pentaho - how to get the index of selected component?


I'm trying to get the index of a selected element using Select Component in CDE Dashboard.

It's very easy:

SELECT id, username FROM table1      
-- this feeds the Select Component

I have "Value as ID" set to FALSE, so the dropdown will show the username and will return the ID as defined in the Parameter field of Select Component.

I need to write some JavaScript code to read both values (ID and username) from the selected option and I have tried it with this.selectedIndex, but it always returns -1.

If I can get the index, I could iterate over the resultSet object and get all the columns.

Also tried with JQuery, but I'm not an expert, though I gave it a try with:

$( "#my_select_component" ).val()

and it didn't work.

If there is an easier way to achieve this, I would highly appreciate it and give feedback.


Solution

  • I ended up with this:

    In PreChange of my_select_component:

    function f(){
    
    $("#my_select_component").on("change", function() {
        Dashboards.setParameter(
            "my_parameter_to_update_titles",
            $(this).find(":selected")[0].innerText
        );
    });
    }