[Product-Developers] Create a datagrid like interface using zope schema

Martin Aspeli optilude at gmx.net
Wed Jul 2 18:34:09 UTC 2008

David Bain-5 wrote:
> Sorry... I know how annoying poorly asked questions are. I usually try to
> take time to formulate my questions.
> Spent too much time explaining :) and not enough time asking.
> right .. so the question:
> Anyone know how to implement something like a datagridwidget using
> zope.formlib?

Formlib widgets are not too hard to write. Look at the wysiwygwidget in
plone.app.form, for example. It's just a class + a template.

I'd probably start off by making a custom field type, deriving from
zope.schema.List. Make it take a list of column definitions as a parameter.
A Column definition can just be a zope.schema field again, e.g.

class IFoo(Interface):
    field = GridField(title=u"My grid", columns=[TextLine(title=u"Name"),

This should be enough to render the grid. The actual storage should be a
list of lists, obviously. The field will need to do some validation and
marshalling, but that's pretty simple. Look at zope.schema.List and its

The widget should probably just look up an IInputWidget for each field and
render that on each cell. Rendering a widget is pretty easy - you adapt
field + request to IInputWidget and call the result, I think.

You'll need to ensure that you get an appropraite set of :list or :records
type form variables. The widget then has a marshaller that looks at the
request and extracts the relevant information, turning it into a list of
lists for the field to consume. You can probably steal a lot of this from
DataGridField in any case.

One interesting option may be to try to use subforms for this, although if
you want JS operations to add rows, re-order and so on, it may be more
trouble than it's worth.

View this message in context: http://www.nabble.com/-Product-Developers--Create-a-datagrid-like-interface-using-zope-schema-tp18241208s20094p18243962.html
Sent from the Product Developers mailing list archive at Nabble.com.

More information about the Product-Developers mailing list