@platform/ui.datagrid
Version:
Isolated tabular DataGrid.
60 lines (59 loc) • 2.62 kB
JavaScript
import { coord } from '../common';
export function sizeHandlers(grid) {
function afterColumnResize(index, width, isDoubleClick) {
if (grid.isInitialized) {
const key = coord.cell.toKey(index, undefined);
width = isDoubleClick
? grid.defaults.columnWidth
: Math.max(grid.defaults.columnWidthMin, width);
grid
.changeColumns({ [key]: toColumn(grid.data.columns[key], { grid: { width } }) }, { source: isDoubleClick ? 'RESET/doubleClick' : 'UPDATE' })
.redraw();
}
}
function afterRowResize(index, height, isDoubleClick) {
if (grid.isInitialized) {
const key = coord.cell.toKey(undefined, index);
height = isDoubleClick
? grid.defaults.rowHeight
: Math.max(grid.defaults.rowHeightMin, height);
grid
.changeRows({ [key]: toRow(grid.data.rows[key], { grid: { height } }) }, { source: isDoubleClick ? 'RESET/doubleClick' : 'UPDATE' })
.redraw();
}
}
function modifyColWidth(width, index) {
var _a, _b;
if (grid.isInitialized) {
const key = coord.cell.toKey(index, undefined);
const column = grid.data.columns[key];
const props = column ? column.props : undefined;
width =
props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.width) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.width : grid.defaults.columnWidth;
}
return width;
}
function modifyRowHeight(height, index) {
var _a, _b;
const key = coord.cell.toKey(undefined, index);
const row = grid.data.rows[key];
const props = row ? row.props : undefined;
height =
props && ((_a = props.grid) === null || _a === void 0 ? void 0 : _a.height) !== undefined ? (_b = props.grid) === null || _b === void 0 ? void 0 : _b.height : grid.defaults.rowHeight;
return height;
}
return {
afterColumnResize,
afterRowResize,
modifyColWidth,
modifyRowHeight,
};
}
const toColumn = (input, props) => {
const res = Object.assign({}, (input || {}));
return Object.assign(Object.assign({}, res), { props: Object.assign(Object.assign({}, (res.props || {})), props) });
};
const toRow = (input, props) => {
const row = Object.assign({}, (input || {}));
return Object.assign(Object.assign({}, row), { props: Object.assign(Object.assign({}, (row.props || {})), props) });
};