3

我有一个ModelAdmin带有MyDataObjecthas_manyAnotherDataObjectSilverStripe 网格字段扩展模块的控制

class TestAdmin extends ModelAdmin {
    static $managed_models = array('MyDataObject');
    static $url_segment = 'testadmin';
    static $menu_title = 'TestAdmin';
}

class MyDataObject extends DataObject {
    private static $db = array('Name' => 'Varchar(255)');
    private static $has_many= array('AnotherDataObjects' => 'AnotherDataObject');

    function getCMSFields() {
        $fields = parent::getCMSFields();

        if ($grid = $fields->dataFieldByName('AnotherDataObjects')) {
            $grid->getConfig()
                ->removeComponentsByType('GridFieldAddExistingAutocompleter')
                ->addComponent(new GridFieldOrderableRows('Priority'));

            $fields->removeByName('AnotherDataObjects');
            $fields->insertAfter($grid,'Name');
        }

        return $fields;
    }
}

class AnotherDataObject extends DataObject {
    private static $db = array(
        'Name'      => 'Varchar(255)',
        'Priority'  => 'Int'
    );
    private static $has_one = array('MyDataObject' => 'MyDataObject');
}

我可以看到调用了“重新排序”,我将如何附加,例如......

alert('Reorder Complete!');

...在系统完成数据库更改后调用?

4

1 回答 1

2

重新排序网格行时不会触发任何事件。但是,您可以重新定义构造函数:

$(".ss-gridfield-orderable tbody").entwine({
        onadd: function() {
            var self = this;

            var helper = function(e, row) {
                return row.clone()
                          .addClass("ss-gridfield-orderhelper")
                          .width("auto")
                          .find(".col-buttons")
                          .remove()
                          .end();
            };

            var update = function(event, ui) {
                // If the item being dragged is unsaved, don't do anything
                var postback = true;
                if (ui.item.hasClass('ss-gridfield-inline-new')) {
                    postback = false;
                }

                // Rebuild all sort hidden fields
                self.rebuildSort();

                // Check if we are allowed to postback
                var grid = self.getGridField();
                if (grid.data("immediate-update") && postback)
                {
                    grid.reload({
                        url: grid.data("url-reorder")
                    }, function(data) {
                        self.onreordered();
                    });
                }
                else
                {
                    var form = $('.cms-edit-form');
                    form.addClass('changed');
                }
            };

            this.sortable({
                handle: ".handle",
                helper: helper,
                opacity: .7,
                update: update
            });
        },
        onreordered: function() {
            console.log('The grid was reordered');
        },
});

它应该在 GridFieldExtensions.js 之后加载

于 2016-09-26T09:29:22.127 回答