PDA

View Full Version : How to extract data from Grid



ByReaL
28 Oct 2011, 1:45 PM
i currently have a GXT 2.2.4 app that makes uses of grids:
Grid<myDataModel1> myGrid1 = new Grid<myDataModel1>(store1, cm1);
Grid<myDataModel2> myGrid2 = new Grid<myDataModel2>(store2, cm2);

now i want to take the data that is in this grids and export it to excel,csv,pdf whatever (i'm already using with success the Apache POI library for that).

normally this is simple since you already have all the data in your data structure my problem is that i want to export exactly what the user is seeing
- user has filters for each row
- user can enable and disable columns
- user can rearrange the columns
- each grid may have a different data model

is there any generic way to obtain the values of all the cells and column headers that are on screen the way they are displayed in a array of arrays of strings or list of lists of strings, so i can dump that into the excel?

sven
29 Oct 2011, 1:27 AM
is there any generic way to obtain the values of all the cells and column headers that are on screen the way they are displayed in a array of arrays of strings or list of lists of strings, so i can dump that into the excel?


I would not follow this way. Wouldnt it be easier the send the user configured data:

- user has filters for each row- user can enable and disable columns
- user can rearrange the columns
- each grid may have a different data model
To the server and filter the list there again and than generate your pdf?

ByReaL
31 Oct 2011, 7:53 PM
It works but the amount of code to be written to extract
- the order of the columns
- the filter settings
- the sorting

and redo all this operations on server and all for each type of data structure associated with different grids, all to get the grids data seams to much when it could be returned directly through a call on the grid (if that exists)

sven
3 Nov 2011, 6:32 AM
The client side cannot generate an excel file cross browser.

Another approach would be to get the list of items from the store and create a custom object that holds the heading and dataindex. This information you can send back to the server and generate your excel file there.

But the nicer approach would be to just send the configuration, as the server already has all the data.

ByReaL
8 Nov 2011, 3:50 PM
yes agreed the client cannot generate the xls file, for creating the file i already have the code written that si not the problem

i believe my question has been already answered:
Q: is there any java call on a grid that returns the data displayed in the grid with column captions etc
A: No

why i was asking that was because i believed it was easier to write code like this:
ArrayofArraysofStrings myData = grid.getTheTable();
myComunicationService.makeAnExcelOnServer (myData , asynccalback onFail /onSucess....)

instead of
sending to server column captions, filters values,
the server re filter and redo all the things done already in the UI
and then do the xls, csv...


and i really do not see any drawback in my suggested approach.
the data anyway ended up on the client from server let's say 1Mb worth of data, now that is filtered and only few columns selected less data than it came to client is sent back to server to make the xls let's say 500Kb those may be extreme cases ( i did not bench marked how much data is transferred for a table with lets say 1000 rows and 20 columns worth of strings with an average of 20 chars)

a drawback may be that usually the download speed is much higher then the upload speed.

sven
9 Nov 2011, 12:57 AM
a drawback may be that usually the download speed is much higher then the upload speed.


Correct. Why would you send data to the server that is already on the server? Only the metadata is missing.