plomino / Plomino

Powerful and flexible web-based application builder
33 stars 37 forks source link

Printable document with Datagrid field #722

Closed giuliadapueto closed 8 years ago

giuliadapueto commented 8 years ago

Hi, I'm working on a Plomino-Plone web page. I created a printable document of a Plomino form with a print-specific layout. My problem is that in the original page I have a datagrid field that is connected to a table in another form, and is possible to insert an indefinable number of row. In the print I would like to see some of this information repeated by the number of rows inserted, that can not be defined when I create the print. The idea is to create a loop (or something like that) based on the number of rows allows you to review the same things with the different information entered in the columns. Is it possible? I started to use Plomino-Plone not long ago and I'm still relatively new in the field, I ask you to use simple terms please. Thanks.

ebrehault commented 8 years ago

Hi,

I think the best approach is create a Computed for display Richtext field in your print form that will render the HTML you want. For instance, if you want to render your datagrid rows as ul/li list you could do:

rows = context.getItem('your_datagrid_field', [])
html = '<ul>'
for row in rows:
    html += '<li>col1=%s col2=%s</li>' % (row[0], row[1])
html += '</ul>'
return html
giuliadapueto commented 8 years ago

Eric thanks for your response. I probably have not explained very well. I need to insert each field of the associated form of the datagrid field within phrases, in different points. Within a larger document, I have a fixed text in which the contents of the datagrid fields must appear in different places (eg. My name is "name_field" , I was born on "birth_field" and I come from "place_field"). This block of text must be repeated for the number of rows one below the other. Could the strategy that you have presented to me be used for this? I understood that this will serve to display bulleted fields one below the other.

djay commented 8 years ago

I think the code I'm working on now for this issue will help with this - https://github.com/plomino/Plomino/issues/637 It will repeat the subform over and over instead of a grid/table. It will do this in edit mode and in read mode too, or you can mix and match. So you would design your subform to have the layout you want. It currently uses headings inserted between the subforms however

screen shot 2016-05-23 at 3 18 55 pm
ebrehault commented 8 years ago

@giuliadapueto yes that's exactly how you can do it. Let's assume your datagried field maps the following fields (in this order): name_field,birth_field,place_field. You could do:

rows = context.getItem('your_datagrid_field', [])
html = ''
for row in rows:
    html += '<p>My name is %s, I was born on %s and I come from %s</p>' % (row[0], row[1], row[2])
return html
giuliadapueto commented 8 years ago

@ebrehault I'm sorry for not having more answered. I used your suggestion and I succeeded in my purpose. Thanks so much Eric!