[MIGX] Исправляем "сжатые" таблицы
Всем привет, есть такая давняя проблема, когда редактируешь ТВ поля MIGX в ресурсах, они изначально «сжаты» влево… Я решил эту проблему, для этого нужен небольшой плагин.

Создаём плагин на событие OnManagerPageBeforeRender, называем например fitMIGXtables
Код:
P.P.S. Плагин будет встроен в мой компонент EclipseUI.

Создаём плагин на событие OnManagerPageBeforeRender, называем например fitMIGXtables
Код:
<?php
/**
* Automatically fits MIGX grid columns on resource create/update pages
*
* @event OnManagerPageBeforeRender
*/
if ($modx->event->name !== 'OnManagerPageBeforeRender') {
return;
}
if (!$modx->controller instanceof modManagerController) {
return;
}
$action = $modx->controller->config['controller'] ?? '';
$isResourcePage = ($action === 'resource/update' || $action === 'resource/create');
if (!$isResourcePage) {
return;
}
$shouldAddScript = false;
$resource = $modx->controller->resource ?? null;
if ($resource instanceof modResource && $resource->get('template')) {
$tvCount = $modx->getCount('modTemplateVarTemplate', [
'templateid' => $resource->get('template')
]);
$shouldAddScript = ($tvCount > 0);
} elseif (is_null($resource)) {
$shouldAddScript = true;
}
if (!$shouldAddScript) {
return;
}
$modx->controller->addHtml(<<<HTML
<script>
Ext.onReady(function() {
function isMIGXGrid(component) {
return component.xtype && component.xtype.startsWith('modx-grid-multitvgrid-');
}
function fitMIGXGridColumns(grid) {
const view = grid.getView();
if (view) {
view.fitColumns();
}
}
function fitAllMIGXGrids() {
Ext.ComponentMgr.all.each(function(component) {
if (isMIGXGrid(component)) {
fitMIGXGridColumns(component);
}
});
}
// Run initially and then periodically
fitAllMIGXGrids();
setInterval(fitAllMIGXGrids, 500);
});
</script>
HTML
);P.S. Плагин добавляет JS только на страницах редактирования ресурсов, где есть хотя бы 1 ТВ поле.P.P.S. Плагин будет встроен в мой компонент EclipseUI.
Комментарии: 10
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
Правда не понял почему?
Вспомнил, прямо сейчас поставил и красота. Спасибо!