I have an iOS application developed in Swift that uses a WKWebView control to display pre-populated AGGrid controls hosted on our website. I am trying to get the selected rows (or nodes) of the embedded AGGrid using their API's getSelectedRows() method. I am using the evaluateJavaScript method of the WKWebView to execute the code in the javascript variable shown below.
func getSelectedRows(completion: @escaping ([String]) -> Void) {
let javascript = """
var gridContainer = document.getElementById('gridInquiry');
var gridInquiry = new agGrid.Grid(gridContainer);
var selectedRows = gridInquiry.getSelectedRows() // I have tried both
// var selectedRows = gridInquiry.api.getSelectedRows() // of these lines
var selectedData = selectedRows.map(function(row) {
return { id: row.id, name: row.name, macAddress: row.macAddress };
});
JSON.stringify(selectedData);
"""
webView.evaluateJavaScript(javascript) { (result, error) in
if let result = result {
print(result)
} else if let error = error {
print(error)
}
}
}
I receive the following error when I execute the code:
WKJavaScriptExceptionMessage=TypeError: gridInquiry.getSelectedRows is not a function. (In 'gridInquiry.getSelectedRows()', 'gridInquiry.getSelectedRows' is undefined)
The javascript code seems to successfully create an instance of the AGGrid called gridInquiry. But, once I have the instance of the grid, I am unable to figure out how to call the AGGrid API getSelectedRows() method.
How can I create an reference to the grid's API so I can access the getSelectedRows() method?