Skip to main content

A table input component for Plone.

Project description

DataGridField

Released under the GNU General Public License

A table input component for the Plone Archetypes framework. Uses JavaScript to make entering tabular data more user friendly process - there are no round trip HTTP requests to the server when inserting or deleting rows.

Features

  • Any number of columns set by a developer

  • Any number of rows filled by a user

  • Insert and deleting rows without submitting a form

  • Many different column types

Requirements

  • Plone 4 (for Plone 3, use the latest release in the 1.7 branch or 1.6 branch, for Plone 2.5, use the latest release in the 1.6 branch)

  • A browser with JavaScript support. There isn’t yet graceful degradation for browsers without JavaScript.

Installation

This version of DataGridField is distributed as an egg at the Python Package index. Information about configuring either for a zope instance house a Plone site can be found by reading the Installing an Add-on Product tutorial.

Once you’ve succesfully done this, you can use the Add/Remove Products screen to install the DataGridField into your site. See below for information about experimenting with the demo types.

How to use

When developing an Archetypes content type you will be able to add a new kind of field: the DataGridField. Low level data stored inside this field will be a Python tuple of dicts.

The widget used for this new type of field is the DataGridWidget.

Field definition

Follow a list of all DataGridField configurations:

columns

A tuple of all columns ids. Default is a single column named “default”.

fixed_rows

A sequence of FixedRow instances that are row values that must exists. If those rows are deleted, they will be re-added when saving the content.

See examples in the code for implementation details.

allow_insert

User can append new rows. Currently is only an UI feature, this is not yet checked at application level. Default is True.

allow_delete

User can delete rows. This is currently UI feature, this is not yet checked at application level. Default is True.

allow_reorder

User can reorder rows. This is currently UI feature, this is not yet checked at application level. Default is True.

searchable

If true all the contents of the DataGridField is concatenated to searchable text and given to text indexer. Default is False.

allow_empty_rows

Set to false to allow empty rows in the data. Default is True.

allow_oddeven

Set to true to hifhligh odd/even rows in edit/view form. Default is False

Widget definition

When defining a new DataGridWidget you can manage following options:

show_header

Choose to display or not table headers in view or edit.

auto_insert

Automatically add new rows when the last row is being edited.

columns

A dict containing columns definition.

This option is not required, but you must provide it for advanced datagrid configuration (see below).

Columns definition

When defining columns (using the columns option in the widget definition above) you must provide a dict composed by:

  • a key that must be found in the columns definition of field.

  • a Column class (or subclass) instance

Every Column instance have following options:

label (required)

The pretty label for the column.

col_description

Additional description for the column scope

default

Default value for every new value of the column

default_method

Like default above, but instead of a static value it must be an attribute for a method that can be called on the context (similar to the default_method of Archetypes fields)

visible

Define if the column will be visible. Default is True.

required

If true, for every provided row, values in this columns must be filled. Default is False.

Apart the simple Column implementation, this product will provide additional kind of columns classes like:

  • SelectColumn

  • LinesColumn

  • LinkColumn

  • RadioColumn

Please refer to the source code for a complete list of columns and details of additional options.

Usage examples

Simple example with three free text columns:

schema = BaseSchema + Schema((

DataGridField('DemoField',
        widget = DataGridWidget(),
        columns=('column1','column2','The third')
        ),
))

Complex example with different column types and user friendly labels:

# Plone imports
from Products.Archetypes.public import DisplayList
from Products.Archetypes.public import *

# Local imports
from Products.DataGridField import DataGridField, DataGridWidget
from Products.DataGridField.Column import Column
from Products.DataGridField.SelectColumn import SelectColumn

class DataGridDemoType(BaseContent):
    """A simple archetype

    """

    schema = BaseSchema + Schema((
        DataGridField('DemoField',
                searchable = True,
                columns=("column1", "column2", "select_sample"),
                widget = DataGridWidget(
                    columns={
                        'column1' : Column("Toholampi city rox",
                                           col_description="Go Toholampi or go home.",
                                           required=True),
                        'column2' : Column("My friendly name"),
                        'select_sample' : SelectColumn("Friendly name", vocabulary="getSampleVocabulary")
                    },
                 ),
         ),

        ))

    def getSampleVocabulary(self):
        """
        """
        """ Get list of possible taggable features from ATVocabularyManager """
        return DisplayList(

            (("sample", "Sample value 1",),
            ("sample2", "Sample value 2",),))

For more examples, see unit test code.

Notes

Since DataGridField 1.5, if you wish to retain old way of automatic row inserting. Here is a bit logic behind all this - otherwise there will be an extra row added when you edit DGF and press save.

  • You must set property auto_insert = True to DataGridWidget

  • You must set property allow_empty_rows = False to DataGridField

Known bugs

  • Sometimes on Firefox column sizes start changing after the user enters some data. Not sure if this is a Firefox bug, though.

  • Prefilled default values work only for text and select columns

  • Radio button and link column postback is not handled properly. This needs fixes very deep into Zope (ZPublisher). If the form validation fails, link column and radio button columns lost their values.

  • Not all types of columns are supported by all browsers because of HTML incompatibilities. See http://www.w3schools.com/tags/tag_input.asp for details.

Demo

A demo type is included. It is disabled by default. This type is neither pretty nor very functional, but demonstrates how a data grid should be used. You can install this type into your site by running the “DataGridField (Example DGF content types)” from the Generic Setup tool within the ZMI.

References

Contributors

People who have been making this true:

Original concept and prototype:

Sponsorship

Organizations paying up for the development:

Changelog

1.9.6 (2017-02-21)

  • Fixed error when used as widget in PloneFormGen 1.7.19 or higher. The widget has no REQUEST attribute there, because it is not acquisition wrapped. [maurits]

1.9.5 (2016-03-22)

  • While hiding a column it is hidden in both view/edit mode without distinction. In “view” mode, while generating the used class ‘dgw-hidden-column’, append the column id so it is possible, like in “edit” mode to use a CSS selector to show a hidden column. [gbastien]

1.9.4 (2015-09-07)

  • Take default value of CheckboxColumn into account while adding a new row in the edit form. [gbastien]

1.9.3 (2015-09-07)

  • Make sure validate_required validates stored data correctly, indeed the orderindex_ key is missing when data is stored. [gbastien]

1.9.2 (2015-08-31)

  • Fixed demotypes registration on modern Plone (Default alias was not working) [keul]

  • Added a real support for Archetypes required attribute. This will probably deprecate the need of the isDataGridFilled validator [keul]

1.9.1 (2014-10-14)

  • added new demo data fields in examples profile [tkimnguyen]

  • removed old nested_scopes imports [tkimnguyen]

  • Added support for many more types of fields (DateColumn, DatetimeColumn, DatetimeLocalColumn, FileColumn, EmailColumn, ColorColumn, PasswordColumn, RangeColumn, MonthColumn, SearchColumn, TimeColumn, UrlColumn, WeekColumn) to match <input> tag types according to http://www.w3schools.com/tags/tag_input.asp Beware not all browsers support these! See that page for browser specific limitations. [tkimnguyen]

  • Portuguese pt-br translation. [lccruz + jtmolon]

  • Replace uses of .gif images from Plone with .png. [maurits]

  • Fixed bug in adding new row. Now new rows inputs has an unique id [cekk]

  • Accessibility fix: wrap command icons inside links so can be reached using keyboard [keul]

  • Prevent a JavaScript error if user try to change row order a single-row table [keul]

  • Accessibility fix: every form field inside columns now has a title attribute that repeat the column’s label [keul]

  • SelectColumn. Removed the value attribute on select HTML tag [keul]

1.9.0 (2013-09-19)

  • Support argument label plus the standard keyword arguments in all Columns: col_description, default, default_method, visible, required. Child classes may support more arguments or keywords arguments. [maurits]

  • No longer support label_msgid in Columns. This was unused for years. [maurits]

  • Change Column.getLabel to support translation again. You should pass a request as the context. [maurits]

  • New column option col_description: display help text for column purpose [keul]

  • New column option required: mark data inside column as required [keul]

  • Added alpha channel to grid icons [keul]

  • Added a visualClear div after the “add new row” button. This fix visual issues when field validation error take place. [keul]

  • Give focus to first column of new added row [keul]

1.8.4 (2013-01-04)

  • added Italian locale [cekk]

1.8.3 (2012-08-23)

  • support for brower view names as ‘vocabulary’ parameter for SelectColumn class

1.8.2 (2012-08-23)

  • added new CSS classes to the manipulator table cells in order to be able to attach custom JS handlers [ajung]

1.8.1 (2012-06-28)

  • Added English locale. Minor internal packaging improvements. [maurits]

1.8.0 (2012-05-29)

  • Strip empty spaces in a list of values. [WouterVH]

  • final 1.8.0 release [ajung]

1.8b2 (2011-05-08)

  • French translation. [thomasdesvenain]

  • Added titles on row manipulators images. [thomasdesvenain]

  • Fixed setting a field value using a base string, using json decoder. Added tests. [thomasdesvenain]

  • fixed check for ‘empty’ for LineColumns [ajung]

1.8b1 (2010-08-16)

  • Register locales directory in zcml. [buchi]

  • Added German translations. [buchi]

1.8a2 (2010-06-02)

  • Fixed Unauthorized error in queryDataGrid when the aq_parent of an object is private, even when we do not actually need any info from that parent. (Change ported from 1.6.2.) [maurits]

  • Added support for Spanish localization [macagua]

  • Added support for i18n [macagua]

  • the TD cells of a rendered DGF field now contain an additional CSS class ‘col-$colnumber’ [ajung]

  • removed pointless Plone==4 pinning in setup.py causing more problems than it actually solves

1.8a1 (2009-11-07)

  • Fixed possible TypeError when submitting the base_metadata form. [maurits]

  • In the view macro use the supplied accessor instead of thinking we know how to get the accessor ourselves as that gives wrong results with LinguaPlone. Fixes http://plone.org/products/datagridfield/issues/14 [maurits]

  • Fixed tests for Plone 4, including a good cleanup. [maurits]

  • Adaptation to work on Plone 4/Zope 2.12. For Plone 3, please use the 1.7 or 1.6 branches. [vincentfretin]

1.7 (unreleased)

  • When there is an empty row with the template_row_marker and validation fails (for any field), make sure we do not end up with two empty rows. [maurits+vpretre]

  • added LinesColumn (used as custom vocabulary source in PFGDataGrid field) [naro]

  • added unique column classnames for thead and tbody table section to identify columns and modify it’s properties through css (specially width for each column seperatly). Now we can remove the style attributes and do some template code cleanup. [saily]

  • allow Products.Archetypes.interfaces.IVocabulary providing objects as Vocabularies. This makes SelectColumn usable in archetypes.schemaextender w/o having to patch the extended class. [jensens]

  • Move installation back to GenericSetup, end of Plone 2.5.x support [andrewb, but real thanks goes to wichert]

1.6 (2009-01-28)

  • Merging of colliding datagridwidget.css and datagridwidget.css.dtml files. Fixes issue #30: http://plone.org/products/datagridfield/issues/30. Which file was ultimately selected appears to be inconsistent. If you’re depending upon an overridden version of either and notice bugs with regards to hidden columns and/or rows appearing or the promise of adding additional DGF rows when using the FixedColumn, you’d be well suited to reconcile your customizations with the merged files from r10445 at: http://dev.plone.org/archetypes/changeset/10445 [andrewb]

1.6rc1

  • Adding Plone 2.5.x DataGridField profile “default_25x” to overcome difference in GS namespace for the registration of our skin directory. Without this, one needed to manually add the correct FSDV within the portal_skins tool for .pt, .dtml, images, etc. to exist with the DataGridWidget’s skins directory. [andrewb]

  • Adding back Extensions and Install.py with install() function for consistent Add/Remove Products experience back to Plone 2.5.x, which did not handle GenericSetup profile-based installation. The install code delegates to Generic Setup for maximal code reuse. The justification is that to completely remove a Add/Remove Product support in Plone 2.5.x between a beta 2 and beta 3 release is overly extreme. This will workaround will be rectified in a future release. [andrewb]

    Note: This was added manually without history because the the eggified version of DataGridField was moved, rather than copied, thus no history at: http://dev.plone.org/archetypes/log/Products.DataGridField?action=follow_copy&rev=&stop_rev=&mode=follow_copy

  • Updated installation instructions, info about example types, and added note about ceasing Plone 2.5.x support [andrewb]

  • Removed check of “@@plone_lock_info” within example types’ GS declarations, so actions render in pre-Plone locking era [andrewb]

  • Made all tests pass in Plone 2.5.x, 3.0.x, and 3.1.x [andrewb]

  • Made explicit names for the different GS profiles that one might choose to install within portal_setup [andrewb]

1.6 beta 3

  • Eggified in Products.AddRemoveWidget [SteveM]

  • Register skin layer correctly. [maurits]

  • Move installation to GenericSetup. [wichert]

  • Removed lots and lots of unneeded import. Pyflakes found that Plone 2.1 support has been broken for a while, so stop claiming it’s still supported. [wichert]

  • Added validator isDataGridFilled (copied from Poi, where it can later be removed). Use this as validator on a DataGridField if you want it to have at least one entry: currently a bogus/hidden entry always remains even when you remove all real entries, so making a DataGridField required has no real effect. See http://plone.org/products/poi/issues/139 and 160. [maurits]

1.6 beta 2

  • Disabled INSTALL_DEMO_TYPES from config.py. [andrewburkhalter]

1.5

  • Pop-up help column by Juan Grigera

  • Added CheckboxColumn by Radim Novotny

  • Plone 3.0 compatible (fixed CMFCorePermissions import)

  • Fixed http://plone.org/products/datagridfield/issues/16 (applied the patch)

  • DataGridField has new property allow_oddeven. Setting this to True will highlight odd end even rows in the view/edit tables. Default: False

  • FixedColumn has optional parameter “visible” (default True). Setting this to False will hide (using css) column from both - view and edit forms.

1.5rc3

  • Added CheckboxColumn. Implementation based on RadioColumn, so there are same bugs. CheckboxColumn lose values if any field on the form raises validation error. Be aware of that, better does not use CheckboxColumn in forms with required fields or fields with validators. [Contributor: naro, radim novotny]

1.5rc2

  • Fixed row adding in IE. This was one of the most horrible debugging session I have had. There was some obscure IE bug which prevented making a DOM node orignally hidden to visible. I created “hacky” workaround for this. Tested in IE 6.0 and FF 1.5.

  • Wolfram Fenske’s I18N patch is disabled, since it doesn’t work in Plone 2.5. The code is almost there. If someone wants to make it complete, it shouldn’t take too much time.

1.5rc1

  • Added workaround for bad DGF initializing which caused empty rows when DGF was created programmatically

1.0 to 1.5

  • Plone 2.5 compatibility guaranteed

  • DGF row manipulators rewritten. Automatically adding new rows feature is now optional, thus making it possible for columns to have prefilled default values without creating a mess. Disabling auto insert is necessary for columns like SelectWidget which don’t have empty default values.

  • Refactored page template code to be more easily extendable. Now CSS file is used for styling DataGridWidgets.

  • New column type: Link column

  • (Wolfram Fenske) I18N patch

    Archetypes widgets have an attribute i18n_domain, which is used to determine which message catalog to use for translation. In DataGridField, this attribute is ignored.

    I have attached a small patch (in fact, smaller than this bug report) which fixes these problems. I didn’t want to introduce a lot of new code, so I did the translation of the labels in the Column class, not in the page template, which might also have been a good way to do it. Since the functions “getLabel()” and “getColumnLabels()” are only called by the page template anyway, I believe this is not an issue. But if you’d rather translate the labels in the page template, please let me know and I’ll write a different patch.

  • (Juan Grigera) Marshaller patch

    I enjoyed your DataGriedField/Widget product for Plone, and would like to contributea small patch/bugfix. In the field mutator (set) the passed value is not always a record, but sometimes a string. In fact the RFC822Marshaller passes a string.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Products.DataGridField-1.9.6.tar.gz (75.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page