Next
Update
Prev

The XML-formatted data is passed by a row unit, and can be manipulated as XMLElement in JavaScript. Click on any cells in the sample Grid, then you will find that the row data will pop up.

var gridApp, gridRoot, dataGrid;
					
function gridReadyHandler(id) {
  gridApp = document.getElementById(id);
  gridRoot = gridApp.getRoot();

  gridApp.setLayout(layoutStr);
  gridApp.setDataURLEx("./Data/DataOneDepthRevenues.xml");

  var selectionChangeHandler = function(event) {				
    var rowIndex = event.rowIndex;				
    var columnIndex = event.columnIndex;
    var dataRow = gridRoot.getItemAt(rowIndex);
    var column = dataGrid.getColumns()[columnIndex];                                                    
    var dataField = column.getDataField();

    var value = getNodeText(dataRow, dataField);
    alert("The parsed value of "+dataField+" is: "+value+"\n\nReceived XML\n\n"+getXmlString(dataRow));
  }

  var layoutCompleteHandler = function(event) {
    dataGrid = gridRoot.getDataGrid();
    dataGrid.addEventListener("change", selectionChangeHandler);
  }

  gridRoot.addEventListener("layoutComplete", layoutCompleteHandler);
}

function getNodeText(xmlElement, nodeName) {
  var node = xmlElement.getElementsByTagName(nodeName)[0];
  if (node != null)
    return node.text ? node.text : node.textContent;
  return null;
}

function getXmlString(xmlElement) {
  if (window.ActiveXObject)
    return xmlElement.xml;
    
  return new XMLSerializer().serializeToString(xmlElement);
}

© 2017 KoolChart. All rights reserved.