Hybrid View

  1. #1
    Ext GWT Premium Member
    Join Date
    Oct 2008
    Posts
    72
    Vote Rating
    5
    elirov is on a distinguished road

      1  

    Default Unanswered: GXT Grid Print/Export CSV feature

    Unanswered: GXT Grid Print/Export CSV feature


    Is there a grid print/export-as-csv feature like the one in SmartGWT?
    It would be nice to be able to get a printable view of the data inside a Store or to put it into a CSV file. I guess we could just take the Store data and show it manually, but that seems like a lot of work, and there may be translations being done by the grid view that should be mirrored in the CSV file or the printable version. Also, sort state, filter state, etc.

    Any ideas?

  2. #2
    Sencha User
    Join Date
    Sep 2012
    Posts
    17
    Vote Rating
    0
    Sam007 is on a distinguished road

      0  

    Default


    Did you get the answer to this question?

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,645
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    This has come up before, and the main answer boils down to this: What looks good on a screen rarely looks good on paper. To be usable, a grid on the screen should keep its header always visible (by way of a scrollbar), but when you print on paper, you can't scroll, so either the header needs to be re-printed at each page (now the page must know how large of a page you are printing too, what orientation, and what zoom...), or just one header at the top.

    Browsers make this even more fun by deciding that any background image shouldn't get drawn on paper, that it is only useful for the screen. This is a problem, as to keep the Grid and other components efficient, we use CSS and the background-image property to keep selection and other styling up to date rather than rewriting the grid for each change.

    My advice is usually to build a simple HTML structure that is well-made for paper or pdf alike, so it can be printed. GXT 3's XTemplates can accept lists, so you can even pass the full contents of a ListStore into it and ask it to render each item into a giant string, which can then be drawn in a new window. The method ListStore.getAll() returns (contrary to its name, we should do something about that) all visible items according to filter state, in order according to the last sort. This allows you to easily pass off the list to a template or some loop that appends elements together to get the full view of all items.

    It may also be possible to get the already rendered inside view of the Grid by reading out the content of the scrolling body - Grid.getView().getBody() returns the element with the contents, and you may be able to copy that or just its html to prepare to print it elsewhere.

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    17
    Vote Rating
    0
    Sam007 is on a distinguished road

      0  

    Default newbie ExtJS

    newbie ExtJS


    I am a newbie can u give an example that I can follow

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,645
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    This isn't ExtJS, this is GXT, a set of widgets that can be used in Java and compiled to JavaScript using the GWT compiler. If you are looking for a ExtJS example, my Java code isn't going to help - try the ExtJS forums instead.

  6. #6
    Sencha User
    Join Date
    Dec 2012
    Posts
    2
    Vote Rating
    0
    mrekim is on a distinguished road

      0  

    Default


    Quote Originally Posted by Colin Alworth View Post
    This has come up before, and the main answer boils down to this: What looks good on a screen rarely looks good on paper.
    A csv file isn't really about what looks good on paper. Maybe some data needs to be presented in a larger report, or someone wants to integrate the data into a complex spreadsheet.

    In any case, with a framework line SmartGWT you can export an existing table (either a grid or a tree grid) with one line of Java code in a button handler. Is this something that can be done in GXT as well?

  7. #7
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,645
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    CSV is different than print, its true, but the question wasn't just 'how can I print this?'. We could probably have a generic way to print all possible grids and turn them into CSVs, but GXT grids are so flexible that there would be many cases that wouldn't make sense. How do you put a slider or a progress bar into a CSV (see http://www.sencha.com/examples/#ExamplePlace:cellgrid)?

    The basic process is pretty simple - iterate through each row, read each column's property, print them into a comma separated string as it makes sense for your use case (any extra formating before CSV, any escaping of characters, etc). In gxt-ish psuedocode:
    Code:
    CSVBuilder builder = new CSVBuilder();
    for (item in store) {
      for (column in grid) {
        builder.formatAndAppend(column.getValueProvider().getValue(item));
      }
      builder.endRow();
    }
    This same strategy can build a quick HTML table that can be used in a popup to print the page - this is more or less what I was suggesting in my first reply.

    Then building the download - as GXT doesn't require certain server components, we can't mandate that you run our special servlet to make this functionality work, and not all browsers can use a data: url to initiate a download. SmartGWT does require this for many of their use cases, which limits some cases where it can work, but also provides a more complete total package if all of your use cases fit in their provided functionality. Just as with the ability to debug GXT components (which are all GWT/Java), and having to do both JS and Java debugging at the same time in SmartGWT (which are mostly wrapped JS), its a tradeoff between the two ways of solving the problem.

    The basic way to build a download is to have the server send back the content of the file to save with a content-type that indicates that the contents are a download. Check out http://stackoverflow.com/questions/6...bits-to-screen for specifics on this. If not using Java Servlets, this approach will be different, but the idea will work for any webserver that can set headers (i.e. all of them).

  8. #8
    Sencha Premium Member
    Join Date
    Oct 2012
    Posts
    201
    Vote Rating
    -6
    vkeswani is infamous around these parts

      0  

    Default


    Colin I was trying to follow the Java approach. I realised that Grid.getView().getBody() returns the table structure html created but not the data inside it? is it possible that once the grid is loaded and Html is generated to get that from the DOM ? Or there is no such method to do that so almost like a snapshot of the grid rendered but in HTML?

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar