Search code examples
gwtdatagridexporter

How to extract Strings from DataGrid regardless of what type contains in GWT


I'am programming a generic DataGrid to Excel exporter. What I wanted to do is to extract an ArrayList which represents the rows, and for each row I have an array of Colomn. So basically, I want to extract an ArrayList<ArrayList<String>>.

The DataGrid have some methods as dataGrid.getColumn(i) or dataGrid.getRowElement(i) but I couldn't find anything to get a String from a specific cell(row,col).

Any idea ?


Solution

  • you can use

    dataGrid.getRowElement(i).getCells().getItem(j);
    

    You would have to write a method to extract all the data and put it in your ArrayList>. Maybe something like that (please note this code was written without any IDE):

    for(int i = 0; i < dataGrid.getRowCount(); i++){
      TableRowElement element = dataGrid.getRowElement(i);
      for(int j = 0; j < element.getCells().getLenght(); j++){
        list.add(element.getCells().getItem(j).toString();
      }
    }
    

    Hope this can help you