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

Editable responsive data #3875

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
Expand Up @@ -27,10 +27,11 @@ export default function(cell, formatterParams, onRendered){
el.addEventListener("click", function(e){
e.stopImmediatePropagation();
toggleList(!config.open);
cell.getRow()._row.dispatch("row-responsive-toggled", cell.getRow(), config.open);
cell.getTable().rowManager.adjustTableSize();
});

toggleList(config.open);

return el;
}
}
66 changes: 57 additions & 9 deletions src/js/modules/ResponsiveLayout/ResponsiveLayout.js
Expand Up @@ -33,12 +33,16 @@ class ResponsiveLayout extends Module{
this.subscribe("column-delete", this.initializeResponsivity.bind(this));

this.subscribe("table-redrawing", this.tableRedraw.bind(this));

if(this.table.options.responsiveLayout === "collapse"){
this.subscribe("row-data-changed", this.generateCollapsedRowContent.bind(this));
this.subscribe("row-init", this.initializeRow.bind(this));
this.subscribe("row-layout", this.layoutRow.bind(this));
}
if(this.table.options.responsiveLayout === "flexCollapse"){
this.subscribe("row-init", this.initializeRow.bind(this));
this.subscribe("row-responsive-toggled", this.toggleFlexRow.bind(this));
}
}
}

Expand All @@ -65,7 +69,7 @@ class ResponsiveLayout extends Module{
column.modules.responsive.index = i;
columns.push(column);

if(!column.visible && this.mode === "collapse"){
if(!column.visible && (this.mode === "collapse" || this.mode === "flexCollapse")){
this.hiddenColumns.push(column);
}
}
Expand Down Expand Up @@ -109,19 +113,50 @@ class ResponsiveLayout extends Module{
column.modules.responsive = {order: typeof def.responsive === "undefined" ? 1 : def.responsive, visible:def.visible === false ? false : true};
}

toggleFlexRow(row, isOpen){
if(isOpen){
row.getElement().classList.add("tabulator-responsive-flex-open");
row.getCells().forEach(function(cell) {
var el = cell.getElement();
var title = cell.getColumn().getDefinition().title;
if(el.style.display === "none") {
el.style.display = 'block';
el.style.width = "100%";
if(title && typeof title !== "undefined"){
el.dataset.label = title;
}
el.classList.add("tabulator-responsive-flex-cell");
}
});
}
else {
row.getElement().classList.remove("tabulator-responsive-flex-open");
row.getCells().forEach(function(cell) {
var el = cell.getElement();
if(!el.classList.contains("tabulator-responsive-flex-cell")){
return;
}
el.style.display = 'none';
el.classList.remove("tabulator-responsive-flex-cell");
});
}
}

initializeRow(row){
var el;

if(row.type !== "calc"){
el = document.createElement("div");
el.classList.add("tabulator-responsive-collapse");
if(this.table.options.responsiveLayout === "collapse"){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this supposed to work? el in L.160 will fail as it will be undefinied.

el = document.createElement("div");
el.classList.add("tabulator-responsive-collapse");
}

row.modules.responsiveLayout = {
element:el,
open:this.collapseStartOpen,
};

if(!this.collapseStartOpen){
if(this.collapseStartOpen){
el.style.display = 'none';
}
}
Expand Down Expand Up @@ -149,9 +184,11 @@ class ResponsiveLayout extends Module{

column.hide(false, true);

if(this.mode === "collapse"){
if(this.mode === "collapse" || this.mode === "flexCollapse"){
this.hiddenColumns.unshift(column);
this.generateCollapsedContent();
if(this.mode === "collapse"){
this.generateCollapsedContent();
}

if(this.collapseHandleColumn && !colCount){
this.collapseHandleColumn.show();
Expand All @@ -166,14 +203,22 @@ class ResponsiveLayout extends Module{
//set column width to prevent calculation loops on uninitialized columns
column.setWidth(column.getWidth());

if(this.mode === "collapse"){
if(this.mode === "collapse" || this.mode === "flexCollapse"){
index = this.hiddenColumns.indexOf(column);

if(index > -1){
this.hiddenColumns.splice(index, 1);
}

this.generateCollapsedContent();
if(this.mode === "collapse"){
this.generateCollapsedContent();
}
if(this.mode === "flexCollapse"){
column.getCells().forEach(function(cell) {
var el = cell.getElement();
el.classList.remove("tabulator-responsive-flex-cell");
});
}

if(this.collapseHandleColumn && !this.hiddenColumns.length){
this.collapseHandleColumn.hide();
Expand Down Expand Up @@ -244,6 +289,9 @@ class ResponsiveLayout extends Module{

if(row.modules.responsiveLayout){
el = row.modules.responsiveLayout.element;
if(!el){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this problem results from L.150 by passing an undefined el.

return;
}

while(el.firstChild) el.removeChild(el.firstChild);

Expand Down