How to get selectedRow data properly from table after change the state of ControlWrapper?

StackOverflow https://stackoverflow.com/questions/23216229

  •  07-07-2023
  •  | 
  •  

Question

How to get selectedRow data properly from table after change the state of ControlWrapper? Here In my table select on first row(after change state using controlWrapper dropdown) returns 0,but I need 3,then only I get proper row data.

var myControlWrapper = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'view': {
        'columns': [1, 2, 3, 4, 7, 8]
    },
    'containerId': 'details_category_filter_container',
    'options': {
        'filterColumnLabel': 'P',
        'ui': {
            'matchType': 'any',
            'label': '',
            'caption': 'All',
            'labelStacking': 'horizontal',
            'allowTyping': false,
            'allowMultiple': false,
        }
    },
    'state': {
        'selectedValues': ['A']
    }
});

var table = new google.visualization.ChartWrapper({
    'chartType': 'Table',
    'containerId': 'my_details_table',
    'options': {
        'allowHtml': true,
        'alternatingRowStyle': true,
        'width': '100%',
        'max-height': '600px'
    }
});


// Create the dashboard.
var details_Table_DashBoard = new google.visualization.Dashboard(document.getElementById('my_details_table')).bind(myControlWrapper, table).draw(view);

google.visualization.events.addListener(table, 'ready', function () {

    google.visualization.events.addListener(table.getChart(), 'select', function () {
        var visualizationTable = table.getChart();

        if (visualizationTable.getSelection()[0] !== undefined) {
            var currentRow = visualizationTable.getSelection()[0].row;

            // Here currentRow returns 0,if I select first row after filtered,but it is third row in view(before filtered)  
            var name = dataTable.getFormattedValue(currentRow, 2);
            var time = dataTable.getFormattedValue(currentRow, 3);


        }
    });
});
Était-ce utile?

La solution

You can reference the data used by the Table by calling the ChartWrapper s getDataTable method:

[edit - added row translation to the underlying DataTable, assumes there are no other DataViews used]

google.visualization.events.addListener(table, 'ready', function () {
    google.visualization.events.addListener(table.getChart(), 'select', function () {
        var visualizationTable = table.getChart();

        if (visualizationTable.getSelection()[0] !== undefined) {
            var currentRow = visualizationTable.getSelection()[0].row;
            var dt = table.getDataTable();
            // get the row index in the underlying DataTable/DataView
            // you will need to do this for each DataView that sits between your ChartWrapper and the base DataTable
            rowIndex = dt.getTableRowIndex(currentRow);

            var name = dataTable.getFormattedValue(rowIndex, 2);
            var time = dataTable.getFormattedValue(rowIndex, 3);
        }
    });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top