Skip to content

Commit

Permalink
add full mode to autocolumns
Browse files Browse the repository at this point in the history
  • Loading branch information
olifolkerd committed Mar 29, 2024
1 parent 1511545 commit 070c3b2
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 133 deletions.
152 changes: 86 additions & 66 deletions dist/js/tabulator_esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23842,13 +23842,13 @@ class ColumnManager extends CoreFeature {

this.contentsElement.insertBefore(this.headersElement, this.contentsElement.firstChild);
this.element.insertBefore(this.contentsElement, this.element.firstChild);

this.initializeScrollWheelWatcher();

this.subscribe("scroll-horizontal", this.scrollHorizontal.bind(this));
this.subscribe("scrollbar-vertical", this.padVerticalScrollbar.bind(this));
}

padVerticalScrollbar(width){
if(this.table.rtl){
this.headersElement.style.marginLeft = width + "px";
Expand Down Expand Up @@ -23888,7 +23888,7 @@ class ColumnManager extends CoreFeature {

return el;
}

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

Expand All @@ -23915,7 +23915,7 @@ class ColumnManager extends CoreFeature {
getElement(){
return this.element;
}

//return containing contents element
getContentsElement(){
return this.contentsElement;
Expand All @@ -23930,19 +23930,19 @@ class ColumnManager extends CoreFeature {
//scroll horizontally to match table body
scrollHorizontal(left){
this.contentsElement.scrollLeft = left;

this.scrollLeft = left;

this.renderer.scrollColumns(left);
}

initializeScrollWheelWatcher(){
this.contentsElement.addEventListener("wheel", (e) => {
var left;

if(e.deltaX){
left = this.contentsElement.scrollLeft + e.deltaX;

this.table.rowManager.scrollHorizontal(left);
this.table.columnManager.scrollHorizontal(left);
}
Expand All @@ -23952,55 +23952,35 @@ class ColumnManager extends CoreFeature {
///////////// Column Setup Functions /////////////
generateColumnsFromRowData(data){
var cols = [],
definitions = this.table.options.autoColumnsDefinitions,
row, sorter;
collProgress = {},
rowSample = this.table.options.autoColumns === "full" ? data : [data[0]],
definitions = this.table.options.autoColumnsDefinitions;

if(data && data.length){

row = data[0];

for(var key in row){
let col = {
field:key,
title:key,
};

let value = row[key];
rowSample.forEach((row) => {

switch(typeof value){
case "undefined":
sorter = "string";
break;

case "boolean":
sorter = "boolean";
break;
Object.keys(row).forEach((key, index) => {
let value = row[key],
col;

case "object":
if(Array.isArray(value)){
sorter = "array";
}else {
sorter = "string";
}
break;

default:
if(!isNaN(value) && value !== ""){
sorter = "number";
}else {
if(value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)){
sorter = "alphanum";
}else {
sorter = "string";
}
if(!collProgress[key]){
col = {
field:key,
title:key,
sorter:this.calculateSorterFromValue(value),
};

cols.splice(index, 0, col);
collProgress[key] = typeof value === "undefined" ? col : true;
}else if(collProgress[key] !== true){
if(typeof value !== "undefined"){
collProgress[key].sorter = this.calculateSorterFromValue(value);
collProgress[key] = true;
}
break;
}

col.sorter = sorter;

cols.push(col);
}
}
});
});

if(definitions){

Expand Down Expand Up @@ -24040,6 +24020,46 @@ class ColumnManager extends CoreFeature {
}
}

calculateSorterFromValue(value){
var sorter;

switch(typeof value){
case "undefined":
sorter = "string";
break;

case "boolean":
sorter = "boolean";
break;

case "number":
sorter = "number";
break;

case "object":
if(Array.isArray(value)){
sorter = "array";
}else {
sorter = "string";
}
break;

default:
if(!isNaN(value) && value !== ""){
sorter = "number";
}else {
if(value.match(/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+$/i)){
sorter = "alphanum";
}else {
sorter = "string";
}
}
break;
}

return sorter;
}

setColumns(cols, row){
while(this.headersElement.firstChild) this.headersElement.removeChild(this.headersElement.firstChild);

Expand All @@ -24048,7 +24068,7 @@ class ColumnManager extends CoreFeature {
this.columnsByField = {};

this.dispatch("columns-loading");

if(this.table.options.rowHeader){
this.rowHeader = new Column(this.table.options.rowHeader === true ? {} : this.table.options.rowHeader, this, true);
this.columns.push(this.rowHeader);
Expand All @@ -24073,7 +24093,7 @@ class ColumnManager extends CoreFeature {
var column = new Column(definition, this),
colEl = column.getElement(),
index = nextToColumn ? this.findColumnIndex(nextToColumn) : nextToColumn;

//prevent adding of rows in front of row header
if(before && this.rowHeader && (!nextToColumn || nextToColumn === this.rowHeader)){
before = false;
Expand Down Expand Up @@ -24131,7 +24151,7 @@ class ColumnManager extends CoreFeature {
var minHeight = 0;

if(!this.redrawBlock){

this.headersElement.style.height="";

this.columns.forEach((column) => {
Expand All @@ -24145,9 +24165,9 @@ class ColumnManager extends CoreFeature {
minHeight = height;
}
});

this.headersElement.style.height = minHeight + "px";

this.columns.forEach((column) => {
column.verticalAlign(this.table.options.columnHeaderVertAlign, minHeight);
});
Expand All @@ -24159,7 +24179,7 @@ class ColumnManager extends CoreFeature {
//////////////// Column Details /////////////////
findColumn(subject){
var columns;

if(typeof subject == "object"){

if(subject instanceof Column){
Expand All @@ -24169,14 +24189,14 @@ class ColumnManager extends CoreFeature {
//subject is public column component
return subject._getSelf() || false;
}else if(typeof HTMLElement !== "undefined" && subject instanceof HTMLElement){

columns = [];

this.columns.forEach((column) => {
columns.push(column);
columns = columns.concat(column.getColumns(true));
});

//subject is a HTML element of the column header
let match = columns.find((column) => {
return column.element === subject;
Expand Down Expand Up @@ -24222,7 +24242,7 @@ class ColumnManager extends CoreFeature {

return index > -1 ? this.columnsByIndex[index] : false;
}

getVisibleColumnsByIndex() {
return this.columnsByIndex.filter((col) => col.visible);
}
Expand Down Expand Up @@ -24304,7 +24324,7 @@ class ColumnManager extends CoreFeature {
}

this.moveColumnActual(from, to, after);

this.verticalAlignHeaders();

this.table.rowManager.reinitialize();
Expand Down Expand Up @@ -24390,12 +24410,12 @@ class ColumnManager extends CoreFeature {
switch(position){
case "middle":
case "center":
adjust = -this.element.clientWidth / 2;
break;
adjust = -this.element.clientWidth / 2;
break;

case "right":
adjust = colEl.clientWidth - this.headersElement.clientWidth;
break;
adjust = colEl.clientWidth - this.headersElement.clientWidth;
break;
}

//check column visibility
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tabulator_esm.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 070c3b2

Please sign in to comment.