gpt4 book ai didi

SilverStripe 网格字段扩展重新排序后的 JavaScript 回调?

转载 作者:搜寻专家 更新时间:2023-10-31 21:02:14 24 4
gpt4 key购买 nike

我有一个 ModelAdminMyDataObject has_many AnotherDataObjectSilverStripe Grid Field Extensions Module那就是控制着

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!');

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

最佳答案

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

$(".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之后加载

关于SilverStripe 网格字段扩展重新排序后的 JavaScript 回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39697619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com