Code Monkey home page Code Monkey logo

silverstripe-gridfieldextensions's Introduction

Silverstripe Grid Field Extensions Module

CI Silverstripe supported module

This module provides a number of useful grid field components:

  • GridFieldAddExistingSearchButton - a more advanced search form for adding items.
  • GridFieldAddNewInlineButton - builds on GridFieldEditableColumns to allow inline creation of records.
  • GridFieldAddNewMultiClass - lets the user select from a list of classes to create a new record from.
  • GridFieldEditableColumns - allows inline editing of records.
  • GridFieldOrderableRows - drag and drop re-ordering of rows.
  • GridFieldRequestHandler - a basic utility class which can be used to build custom grid field detail views including tabs, breadcrumbs and other CMS features.
  • GridFieldTitleHeader - a simple header which displays column titles.
  • GridFieldConfigurablePaginator - a paginator for GridField that allows customisable page sizes.

This branch will aim for compatibility with Silverstripe 4.x.

Installation

composer require symbiote/silverstripe-gridfieldextensions:^3

For Silverstripe 3.x, please see the compatible branch.

See docs/en/index.md for documentation and examples.

silverstripe-gridfieldextensions's People

Contributors

adrexia avatar ajshort avatar briceburg avatar dhensby avatar dnsl48 avatar drmartingonzo avatar emteknetnz avatar flxqr2 avatar guysartorelli avatar jakeb-blissmedia avatar jelicanin avatar josephlewisnz avatar kinglozzer avatar mattclegg avatar mfendeksilverstripe avatar nicole-ashley avatar nightjar avatar ntd avatar nyeholt avatar oilee80 avatar pief avatar robbieaverill avatar sabina-talipova avatar scopeynz avatar silbinarywolf avatar spekulatius avatar sunnysideup avatar thomasbnielsen avatar wilr avatar zauberfisch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silverstripe-gridfieldextensions's Issues

Filtering $Items

I've implemented a means to filter results used by the GridFieldAddExistingSearchButton in the pickerfield module... although feel that this feature is probably better off in your [native] gridfieldextensionsmodule module. I'll open a pull request featuring my implementation if you think it's a good fit. Example usage is;

$fields->addFieldsToTab('Root.Pedigree', array(
    $filterField = new PickerField('Owners', 'Owners', $this->Owners());
    // ...
));
$filterField->setSearchFilters(array('Status' => 'active'));

Thanks for your [as always!] awesome module(s).

Feature: add sortorder onbeforewrite in orderablegridfield for Many_Many relations

As also described in #44 writing a sortorder onbeforesave, is sometimes needed (adding items to bottom of list). In #44 you gave an example of setting an initial sortorder for has_many relations - but i need to do the same for many_many relations.

I tried to have a look at it myself, but to complicated for my skills.
Had some input from Zauberfisch on irq:
[12:24pm] Zauberfisch: subclass the GridFieldOrderableRows, and overwite the list "getter", and if items in that list have a sort of 0, set it to count + 1
[12:24pm] Zauberfisch: (actually max + 1 again)

Travis CI

Travis CI fails with this problem:

Problem 1

  • Installation request for silverstripe/framework 4.0.x-dev -> satisfiable by silverstripe/framework[4.0.x-dev].
  • silverstripe/framework 4.0.x-dev requires php >=5.4.0 -> no matching package found.

Can we fix this?

Many_many sorting writing same sortorder across multible DO

When sorting DataObjects that are related to many pages or other dataobjects, the same sort order is written to all DataObjects across relations.

Ex: item 1,2,3 on page 1 is sorted as 1,2,3. Adding the same items to page 2 and sorting these as 3,2,1 -> now page 1 items are sorted as 3,2,1 also.

Multi class add not working with locale

The multiclass add dropdown doesn't appear to be working. The add-multi-class/ is being appended after the query parameters on the URL (such as locale), with the query parameters being re-appended.

e.g. I assume it should be

ItemEditForm/field/<RELATIONSHIP>/add-multi-class/<CLASSNAME>?locale=en_GB

but is actually

ItemEditForm/field/<RELATIONSHIP>?locale=en_GB/add-multi-class/<CLASSNAME>&locale=en_GB&/<CLASSNAME>&locale=en_GB

not found for many_many sort

after dragging I get an "not found" error it s a 404

class OnePage extends Page{

private static $many_many=array(
    'Pages'=>'BoxedPage'
);
private static $many_many_extraFields = array(
   'Pages' => array(
         'SortID' => 'Int'
    )
);
public function getCMSFields(){     
    $fields=parent::getCMSFields();
        $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
            new GridFieldOrderableRows('SortID')
        );          
        $contentObjects = new GridField("Pages", "Inhalte linke Spalte", $this->Pages()->sort('SortID'), $gridFieldConfig);
        $dataColumns = $contentObjects->getConfig()->getComponentByType('GridFieldDataColumns');
        $dataColumns->setDisplayFields(array(
            'CustomTitle' => 'Titel',
            'SortID'=>'SortID'              
        ));     

class BoxedPage extends Page{
private static $belongs_many=array(
'Pages'=>'OnePage'
);

Examples

Some basic examples of how to use the components

ManyManyList breaks GridFieldEditableColumns if there are no extra fields

If many_many relation has no extra fields the script breaks with the following error:
[Warning] array_key_exists() expects parameter 2 to be array, null given GET /admin/pages/edit/EditForm/field/Menu/item/1/edit Line 152 in \gridfieldextensions\code\GridFieldEditableColumns.php

The solution is just to add the extra check at line 151:

if(!$field && $list instanceof ManyManyList) {
    $extra = $list->getExtraFields();

    if($extra)
        if(array_key_exists($col, $extra)) {
            $field = Object::create_from_string($extra[$col], $col)->scaffoldFormField();
        }
}

Version tagging

Would it be possible to start tagging revisions on this repo? I submitted #94 recently and really need it in our composer project, but the module is pulled in via another module's dependencies so I can't require dev-master.

Throws 500 error when GridFieldOrderableRows is used in a ModelAdmin

Upon drag & drop, error 500 is thrown with "Action 'reorder' isn't available on class GridField."

class TradeCategoryModelAdmin extends ModelAdmin {

    private static $menu_title = 'Trade Categories';
    private static $managed_models = array('TradePage_Category');
    private static $url_segment = 'tpc';

    public function getEditForm($id = null, $fields = null) {
        $form = parent::getEditForm($id, $fields);
        $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
        if ($gridField instanceof GridField) {
            $gridField->getConfig()->addComponent(new GridFieldOrderableRows('SortOrder'));
        }
        return $form;
    }

}

class TradePage_Category extends DataObject {

    private static
            $db = array(
                'Name' => 'Varchar(1024)',
                    ),
            $has_many = array(
                'TradePage_Items' => 'TradePage_Item',
                    ),
            $default_sort = 'Name ASC';
…
}

Documentation for more complex fields.

Would it be possible to get some pointers on how to add more complexfields?

For eg

Image upload Fields, TreeDropdown Fields etc?

Thanks. Great plugin. much appreciated.

Request: Saving GridFieldEditableColumns inline

I really like adding editable fields directly on the gridfield, but I was wondering if it would be within scope of this module to allow these to be written?

Two ways I could imagine this working, a new save/write button, or doing this automatically when the field loses focus.

OrderableRows dragging an Item to the next page

Hi AJ, when my List gets longer than the height of my Browserwindow (so that the scrollbar appears on the right), I'm unable to draop an Item to the next/prev Page arrow.

How can I fix this Problem?

Stable composer release

Do you plan on doing a stable release (composer tag) at any stage?

I believe doing so will help people have confidence in the module, and also it provides a reference point to see if your local code is up-to-date without needing to look at git logs.

It also means less risk of things breaking during composer update, as long as semantic versioning is respected. https://getcomposer.org/doc/01-basic-usage.md#package-versions

I'm personally relying on this module more and more, and I'm sure others are too. It's a great set of grid improvements.

Typo in silverstripe-gridfieldextensions/lang/de_DE.yml

de_DE:
GridFieldAddExistingSearchHandler.ss:
NOITEMS: 'Kein Ergebnis'
RESULTS: 'Ergebnisse'
GridFieldExtensions:
ADD: 'Hinzufügen'
ADDEXISTING: 'Bestenden Eintrag hinzufügen' <-------- !! Bestehenden !! ---------->
SEARCH: 'Suche'
SELECTTYPETOCREATE: '(Bitte Typ wählen)'

Add scrutinizer support

Could you please add the module to scrutinizer? https://scrutinizer-ci.com/g/new. We're keeping track of all modules we use on our contributions dashboard (github-dashing.herokuapp.com), and I've added scrutinizer quality and coverage scores there. Doesn't require any config, just four clicks.

We're experimenting with a more fine tuned config, including code coverage running on travis, but that's not really to roll out yet (https://github.com/stojg/silverstripe-timeline). Happy to hear feedback and get help of course :)

Adding columns from relations to EditableColumns restults in error

with gridfield (& summay fields) using the GridFieldDataColumns you can also include relations, eg Image.Title where Image is a has_one relation.
This will then be resolved to the title of the image.

in Editable Columns, this results in an error, because it stores FormFields with the specified name, which also contains the ..
However, FieldList will use the dot syntax for something else: nested fields (CompositeFields). So creating the field works, but things like $fields->fieldByName('Image.Title') will not search for Image.Title instead it will search for a field Title inside a field Image, which does not exist.

So fieldByName returns null instead of the desired field, leading to the error:

Fatal error: __clone method called on non-object in /vagrant/www/gridfieldextensions/code/GridFieldEditableColumns.php on line 33

I am sure, that is just the first rock on the road to supporting relation fields, I am guessing saving wouldn't work even if the field did.
But perhaps starting with read only fields would be a good thing?

version bump?

can I suggest that the version be bumpd to 1.0.1 or 1.1.0 since we've seen a few fixes and/or updates to this module

Feature: add sortorder onbeforewrite in orderablegridfield

I just realised today, that the sortorder is allways set as 0 when a object is written.
This is fine when creating the initial list, but when you have sortes the list, newly added items get added to the top often not the desired result)

The module https://github.com/UndefinedOffset/SortableGridField has some code in place for handling this (add to top or borttog of list), could you perhaps borrow some of that code or perhaps create an example of a onbeforewrite function that would do this?

I think this module really needs the above functionality as the normal/expected behaviour is that items are added at the bottom of lists.

Error on adding new Objects

I have GridFieldAddNewMultiClass configured so it can add 3 Different Objects:

$multiclass = new GridFieldAddNewMultiClass();
$multiclass->setClasses(array("Beeld", "Film", "Audio"));

My $has_many list looks like this:

public static $has_many = array(
"Beelden" => "Beeld"
);

When i add a "Beeld" it works, but when i add a "Film" or "Audio" it does not work. How do i need to configure the $has_many list to work with different types?

FIX: Compatibility with versioned DataObjects

As in #21 it would be great if the GridFieldOrderableRows supported versioned DataObjects. So I thought it would be good to start a discussion regarding the best solution as I agree with @ajshort that coupling the components should be avoided.

My suggestion is that the current implementation that uses DB::query() to update the sort order is replaced with DataObject::write(). This would ensure that all the relevant pre/post write code gets run (including all the versioned related code).

However I recognise that this will add a certain amount of overhead to re-ordering, is this acceptable or is there a more elegant solution?

Can we list any other field beyond "Title" in search results?

Hi there,

This is not an "issue" per se, I was just wondering if there's some way to list a different field in the search results instead of "Title" (or more than one fields).

The reason I ask for this should be quite obvious, there are many cases where the "Title" is not enough for the user to decide which record is the correct one to pick (many people can share the same name for example). In these cases it would be nice if we could have extra fields listed in the results such as "Code", or "Mobile" etc.

Even if multiple fields cannot be listed due to limitations in the module, a slightly inelegant workaround would be to get all the relevant info by just creating (and populating) a new column in the dataobject with all required info concatenated. For example:
"ExtendedAlternativeTitle" :
CD0001 - John Smith - 935212541 - [email protected] - 10, Lancelot Str. etc...

I just need to be able to select a different field. Any idea how can I make this work?

Cheers!
alt_column

Many_many sorting not writing a sort order?

I'm using your module for my section module: https://github.com/NobrainerWeb/Silverstripe-Section-Module/, i have just created a new branch that is going to have the relation between Sections and Pages as many_many https://github.com/NobrainerWeb/Silverstripe-Section-Module/tree/Many-many.

For this i would also like to use your module (no need for another requirement), however i'm not able to get the sorting working.

Could you have a look at the two files and see if i did something wrong?:
https://github.com/NobrainerWeb/Silverstripe-Section-Module/blob/Many-many/code/SectionModule.php
https://github.com/NobrainerWeb/Silverstripe-Section-Module/blob/Many-many/code/dataobjects/Section.php

The extraField is added to the relation table, but the value is just 0 for the records, even after sorting.

Hope someone can help :-)

After sorting, rows disappear

After drag-dropping a row, the rows all disappear, however sorting is maintained.

To fix this, I edited GridFieldExtension.js.

After the line (193) with the call to:
grid.reload({
url: grid.data("url") + "/reorder",
data: data.get()
});

I added:
grid.reload({
url: grid.data("url"),
data: data.get()
});

This refreshes the rows after sorting them.

Tag to reflect recent repo change

Recent change of repository ownership on github/packagist means that dependencies will now be broken....because composer stable downloads a tarball zip from the git repo.

  Failed to download ajshort/silverstripe-gridfieldextensions from dist:
The "https://api.github.com/repos/ajshort/silverstripe-gridfieldextensions/zipball/067608506752dbc0ff2542f08cc9e9184a5eb475" 
file could not be downloaded (HTTP/1.1 404 Not Found)

I think if you do a v1.0.2 tag, it should resolve things.

GridFieldExportAllButton

The GridField unfortunately only offers a export button for the currently displayed rows, not for all rows.

@bummzack has already done a fine job at tackling this issue and created a component, see the stackoverflow post: http://stackoverflow.com/a/17503504/1119263

I often run into the demand for an export all button, question is: do we want to merge it into your module @ajshort or create a new module for it?

Also, I am hoping @bummzack will reply here and voice his wishes (I have not received a response to my comment on stackoverflow).
Best case scenario is that @bummzack creates a pull request or module, then we would not have any license issues.
If not, I am willing to rebuild such a component and create a pull request for it.

(or copy paste it from there, have to check how code posted there is licensed)

GridFieldEditableColumns & Checkboxes

Using this component for a many_many_extrafield (Boolean or Int) with a CheckboxField allows me to set the value, but not unset.

I've tested with both array & closure, same results. Is this a bug in GFE?

many_many_extraFields and GridFieldEditableColumns bypass formfield dataValue function and possibly more

How to reproduce the bug

composer create-project silverstripe/installer ~/Sites/newproject 3.1.0-beta2 
composer require ajshort/silverstripe-gridfieldextensions:*

Page.php & TestObject.php

When using many_many_Extrafields and GridFieldEditableColumns with Decimal data type.

Use the inline Add button to add new row and then try to save the blank values.

Error at framework/model/MySQLDatabase.php line 580: Couldn't run query: 
INSERT INTO "Page_TestObjects" ("ExtraDecimal", "TestObjectID", "PageID") VALUES (null, 5, 1) 

Column 'ExtraDecimal' cannot be null (http://localhost/gridfieldextensions/admin/pages/edit/EditForm)

The NumericField dataValue() method is being called and that should make sure there is at least '0' in the field but for some reason the extrafield doesn't take that into account.

When manually setting the dataValue() to some arbitrary number all the other fields save that arbitrary value. Not so with the extrafield.

GridFieldOrderableRows doesn't work when used for related data objects of an unsaved parent data object

This commit 4015d33 changes $sortterm passed to ArrayList#sort method which assumes that only column name is quoted not the table name. See here: https://github.com/silverstripe/silverstripe-framework/blob/3.2/model/ArrayList.php#L363

When a data object class 'Parent' has a has_many relation with data object class 'Child' named 'Children' and I want to create new 'Parent' data object it raises exception and doesn't show 'Parent' form.

When I override Children method on 'Parent' class like this it works but it is a workaround I don't like:

public function Children()
{
    if (empty($this->ID))
    {
        return Child::get()->filter(array('ParentID' => $this->ID))->sort('SortOrder');
    }
    else
    {
        return parent::Children();
    }
}

EditableColumns do not save when used in Model Admin

When replacing a ModelAdmin gridfield with inline editing fields, new rows are not saved (either by clicking add button or hitting enter from previous row) .

Replicate by using the following function in a ModelAdmin extension (replacing gridfield name):

    public function getEditForm($id = null, $fields = null) {

        $form = parent::getEditForm($id, $fields);

        if ($blockGridField = $form->Fields()->fieldByName('MemberProfileOption')) {
            $config = $blockGridField->getConfig();
            $config->removeComponentsByType('GridFieldAddNewButton');
            $config->removeComponentsByType('GridFieldPrintButton');
            $config->removeComponentsByType('GridFieldExportButton');
            $config->removeComponentsByType('GridFieldDataColumns');
            $config->addComponent(new GridFieldEditableColumns());
            $config->addComponent(new GridFieldAddNewInlineButton());
            $config->addComponents(new GridFieldOrderableRows());

            $config->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array(
                'ClassName'  => function($record, $column, $grid) {
                    return new DropdownField($column, 'Type', Singleton('MemberProfileOption')->getClassTypeArray());
                },
                'Title' => function($record, $column, $grid) {
                    return new TextField($column);
                }
            ));
        }

        return $form;
    }

Missing license

There's no license for this module. Please include one, so people can use it :)

Delete reloads grid

inline editable grid allows to delete entries, but on delete the gridfield gets reloaded and all unsaved changes are lost.
This problem only occurs on deleting already saved records, newly created rows that have not yet been saved can be deleted without this problem

3.1 or/and 3.0

Is this module really only for SS3.1 as stated in composer?

"silverstripe/framework": ">=3.1"

If so what does it take to make a 3.0 branch?

GridFieldEditButton return "Not found"

Hi I need to be able to open the Dataobject to edit more fields an upload Images, etc. but when clicking the editbutton,.. silverstripe return a "not found" error... ss 3.1.10

Impossible to use UploadField

If you would do something like this:

        $grid->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array(
            'PhotoID' => array(
                'title' => 'Photo',
                'callback' => function($record, $column, $grid) {
                    return new UploadField('PhotoID');
                }
            )
        ));

You would get something like this:

Fatal error: Call to a member function FormAction() on a non-object in ../framework/forms/FormField.php on line 161

Throws an error on a many_many relationship

Hi,

I have been using your module and its great and works perfectly on a has_many DO. When I tried using it on a many_many DO it throws an error. Just an FYI but would love to it if it gets fixed. :)

Missing _config.php

module seems to be missing a _config.php in the root folder file so classes are not being picked up

GridFieldEditableColumns loses column title on closure

When using the closure approach as in FirstField example, the column title is missing in the GridFIeldTitleHeader. It appears as expected when the title/field params are used instead.

$grid->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array(
    'FirstField'  => function($record, $column, $grid) {
        return new TextField($column);
    },
    'SecondField' => array(
        'title' => 'Custom Title',
        'field' => 'ReadonlyField'
    )
));

GridFieldEditableColumns doesn't work with DateTimeField

Attempting to display a DateTime field, the values input do not save, resulting in NULL across all records for the column.

It appears that the id and name attributes of the form field are the same for all records, taking the form [ColumnName][date] and [ColumnName][time]. And additional complication created by this are the Javascript calendars; changing the value for any record only changes the value in the first record (and none of it's saved anyway).

Forcing the $name parameter in construction of the DateTimeField to take the GridName[Class][RecordNumber][FieldName] format used by GridFieldAddNewInlineButton results in a PHP Fatal error: call to member function setName() on a non-object in GridFieldAddNewInlineButton line 98.

This manifests whether or not setDisplayFields is used, and in both array and callback uses of setDisplayFields.

CMS actions bar appears at the top of the page on a 'hard' refresh

On pages with the inline add component enabled: after a hard refresh, the actions bar (for editing a page, haven't checked on ModelAdmin) moves to the top of the page - it doesn't get any inline styling added to position it like it should:

screen shot 2013-05-21 at 10 25 00

The cause is the <script> tags wrapping the content of the template GridFieldAddNewInlineRow.ss. Exactly why this causes an issue I don't know, but removing the tags solves it.

Sorting a GridField within a ModelAdmin record is throwing a 404

If you have a DataObject managed in model admin, and that DO has a sortable GridField, the URL to the reorder action 404s. Example:

/admin/foo/Foo/EditForm/field/Foo/item/150/ItemEditForm/field/RandomThings/reorder

"I can't handle sub-URLs of a GridFieldDetailForm_ItemRequest object."

column titles are missing

without column titles its kinda impossible to know what are you adding/editing unless you know what fields are there...
No column Names

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.