Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding options to ColumnComponent#setWidth #3964

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/js/core/column/Column.js
Expand Up @@ -69,6 +69,10 @@ class Column extends CoreFeature{
this._initialize();
}

get widthInitiallyFixed() {
return !!this.definition.width;
}

createElement (){
var el = document.createElement("div");

Expand Down Expand Up @@ -836,6 +840,7 @@ class Column extends CoreFeature{
//set width if present
if(typeof this.definition.width !== "undefined" && !force){
// maxInitialWidth ignored here as width specified
console.log("reinitializeWidth", "setWidth");
this.setWidth(this.definition.width);
}

Expand All @@ -852,7 +857,7 @@ class Column extends CoreFeature{
return;
}

if(!this.widthFixed){
if(!this.widthInitiallyFixed){
this.element.style.width = "";

this.cells.forEach((cell) => {
Expand All @@ -861,8 +866,12 @@ class Column extends CoreFeature{
}

var maxWidth = this.element.offsetWidth;
console.log("fitToData[mid]", this.getField(), { maxWidth, width: this.width, fixed: this.widthInitiallyFixed });
if (this.getField() === 'description') {
window.col = this;
}

if(!this.width || !this.widthFixed){
if(!this.width || !this.widthInitiallyFixed){
this.cells.forEach((cell) => {
var width = cell.getWidth();

Expand All @@ -871,11 +880,13 @@ class Column extends CoreFeature{
}
});


if(maxWidth){
var setTo = maxWidth + 1;
if (this.maxInitialWidth && !force) {
setTo = Math.min(setTo, this.maxInitialWidth);
}
console.log("fitToData", this.getField(), "setting", { setTo, force, mI: this.maxInitialWidth });
this.setWidthActual(setTo);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/js/core/column/ColumnComponent.js
Expand Up @@ -139,9 +139,11 @@ export default class ColumnComponent {

setWidth(width){
var result;

if(width === true){
result = this._column.reinitializeWidth(true);
} else if(width === 'initial') {
result = this._column.reinitializeWidth(false);
}else{
result = this._column.setWidth(width);
}
Expand All @@ -150,4 +152,4 @@ export default class ColumnComponent {

return result;
}
}
}
19 changes: 18 additions & 1 deletion src/js/modules/Persistence/Persistence.js
Expand Up @@ -190,6 +190,23 @@ class Persistence extends Module{
}

setColumnLayout(layout){
const autoSize = [];
layout.forEach((layoutItem) => {
if ([true, 'initial'].includes(layoutItem.width)) {
autoSize.push({...layoutItem});
delete layoutItem.width;
}
});

autoSize.forEach((c) => {
const candidate = this.table.columnManager.getColumnByField(c.field);
console.log('candidate', candidate);
if (candidate) {
candidate.getComponent().setWidth(c.width);
const update = layout.find((l) => l.field === c.field);
if (update) update.width = candidate.getComponent().getWidth();
}
});
this.table.columnManager.setColumns(this.mergeDefinition(this.table.options.columns, layout));
return true;
}
Expand Down Expand Up @@ -455,4 +472,4 @@ Persistence.moduleInitOrder = -10;
Persistence.readers = defaultReaders;
Persistence.writers = defaultWriters;

export default Persistence;
export default Persistence;