Skip to content

Commit 540e5c2

Browse files
committed
fix 24 hour time formatting in time and datetime editors
1 parent 89c5127 commit 540e5c2

File tree

4 files changed

+63
-36
lines changed

4 files changed

+63
-36
lines changed

dist/js/tabulator_esm.js

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6049,12 +6049,14 @@ function time(cell, onRendered, success, cancel, editorParams){
60496049
newDatetime = DT.fromFormat(String(cellValue), inputFormat);
60506050
}
60516051

6052-
cellValue = newDatetime.toFormat("hh:mm");
6052+
cellValue = newDatetime.toFormat("HH:mm");
60536053

60546054
}else {
60556055
console.error("Editor Error - 'date' editor 'format' param is dependant on luxon.js");
60566056
}
60576057
}
6058+
6059+
console.log("val", cellValue);
60586060

60596061
input.value = cellValue;
60606062

@@ -6176,7 +6178,7 @@ function datetime(cell, onRendered, success, cancel, editorParams){
61766178
newDatetime = DT.fromFormat(String(cellValue), inputFormat);
61776179
}
61786180

6179-
cellValue = newDatetime.toFormat("yyyy-MM-dd") + "T" + newDatetime.toFormat("hh:mm");
6181+
cellValue = newDatetime.toFormat("yyyy-MM-dd") + "T" + newDatetime.toFormat("HH:mm");
61806182
}else {
61816183
console.error("Editor Error - 'date' editor 'format' param is dependant on luxon.js");
61826184
}
@@ -11068,6 +11070,7 @@ class FrozenColumns extends Module{
1106811070
this.subscribe("column-deleted", this.reinitializeColumns.bind(this));
1106911071
this.subscribe("column-hide", this.reinitializeColumns.bind(this));
1107011072
this.subscribe("column-show", this.reinitializeColumns.bind(this));
11073+
this.subscribe("columns-loaded", this.reinitializeColumns.bind(this));
1107111074

1107211075
this.subscribe("table-redraw", this.layout.bind(this));
1107311076
this.subscribe("layout-refreshing", this.blockLayout.bind(this));
@@ -20067,6 +20070,13 @@ class Range extends CoreFeature{
2006720070
this.table = table;
2006820071
this.start = {row:0, col:0};
2006920072
this.end = {row:0, col:0};
20073+
20074+
if(this.rangeManager.rowHeader){
20075+
this.left = 1;
20076+
this.right = 1;
20077+
this.start.col = 1;
20078+
this.end.col = 1;
20079+
}
2007020080

2007120081
this.initElement();
2007220082

@@ -20126,14 +20136,14 @@ class Range extends CoreFeature{
2012620136

2012720137
if (element.type === "column") {
2012820138
if(this.rangeManager.columnSelection){
20129-
this.setStart(0, element.getPosition() - 2);
20139+
this.setStart(0, element.getPosition() - 1);
2013020140
}
2013120141
}else {
2013220142
row = element.row.position - 1;
20133-
col = element.column.getPosition() - 2;
20143+
col = element.column.getPosition() - 1;
2013420144

2013520145
if (element.column === this.rangeManager.rowHeader) {
20136-
this.setStart(row, 0);
20146+
this.setStart(row, 1);
2013720147
} else {
2013820148
this.setStart(row, col);
2013920149
}
@@ -20147,18 +20157,18 @@ class Range extends CoreFeature{
2014720157
if (element.type === "column") {
2014820158
if(this.rangeManager.columnSelection){
2014920159
if (this.rangeManager.selecting === "column") {
20150-
this.setEnd(rowsCount - 1, element.getPosition() - 2);
20160+
this.setEnd(rowsCount - 1, element.getPosition() - 1);
2015120161
} else if (this.rangeManager.selecting === "cell") {
20152-
this.setEnd(0, element.getPosition() - 2);
20162+
this.setEnd(0, element.getPosition() - 1);
2015320163
}
2015420164
}
2015520165
}else {
2015620166
row = element.row.position - 1;
20157-
col = element.column.getPosition() - 2;
20167+
col = element.column.getPosition() - 1;
2015820168
isRowHeader = element.column === this.rangeManager.rowHeader;
2015920169

2016020170
if (this.rangeManager.selecting === "row") {
20161-
this.setEnd(row, this._getTableColumns().length - 2);
20171+
this.setEnd(row, this._getTableColumns().length - 1);
2016220172
} else if (this.rangeManager.selecting !== "row" && isRowHeader) {
2016320173
this.setEnd(row, 0);
2016420174
} else if (this.rangeManager.selecting === "column") {
@@ -20240,11 +20250,11 @@ class Range extends CoreFeature{
2024020250
}
2024120251

2024220252
atTopLeft(cell) {
20243-
return cell.row.position - 1 === this.top && cell.column.getPosition() - 2 === this.left;
20253+
return cell.row.position - 1 === this.top && cell.column.getPosition() - 1 === this.left;
2024420254
}
2024520255

2024620256
atBottomRight(cell) {
20247-
return cell.row.position - 1 === this.bottom && cell.column.getPosition() - 2 === this.right;
20257+
return cell.row.position - 1 === this.bottom && cell.column.getPosition() - 1 === this.right;
2024820258
}
2024920259

2025020260
occupies(cell) {
@@ -20256,7 +20266,7 @@ class Range extends CoreFeature{
2025620266
}
2025720267

2025820268
occupiesColumn(col) {
20259-
return this.left <= col.getPosition() - 2 && col.getPosition() - 2 <= this.right;
20269+
return this.left <= col.getPosition() - 1 && col.getPosition() - 1 <= this.right;
2026020270
}
2026120271

2026220272
overlaps(left, top, right, bottom) {
@@ -20325,7 +20335,7 @@ class Range extends CoreFeature{
2032520335
}
2032620336

2032720337
getColumns() {
20328-
return this._getTableColumns().slice(this.left + 1, this.right + 2);
20338+
return this._getTableColumns().slice(this.left, this.right + 1);
2032920339
}
2033020340

2033120341
clearValues(){
@@ -20511,7 +20521,7 @@ class SelectRange extends Module {
2051120521

2051220522
initializeColumn(column) {
2051320523
if(this.columnSelection && column.definition.headerSort && this.options("headerSortClickElement") !== "icon"){
20514-
console.warn("Using column headerSort with selectableRangeColumns option may result in unpredictable behavior");
20524+
console.warn("Using column headerSort with selectableRangeColumns option may result in unpredictable behavior. Consider using headerSortClickElement: 'icon'.");
2051520525
}
2051620526

2051720527
if (column.modules.edit) ;
@@ -20806,7 +20816,7 @@ class SelectRange extends Module {
2080620816
nextCol = Math.max(nextCol - 1, 0);
2080720817
break;
2080820818
case "right":
20809-
nextCol = Math.min(nextCol + 1, this.getTableColumns().length - 2);
20819+
nextCol = Math.min(nextCol + 1, this.getTableColumns().length - 1);
2081020820
break;
2081120821
case "up":
2081220822
nextRow = Math.max(nextRow - 1, 0);
@@ -20900,13 +20910,14 @@ class SelectRange extends Module {
2090020910
findJumpCellLeft(rowPos, colPos){
2090120911
var row = this.getRowByRangePos(rowPos),
2090220912
cells = row.cells.filter((cell) => cell.column.visible),
20903-
isStartingCellEmpty = !cells[colPos + 1].getValue(),
20913+
isStartingCellEmpty = !cells[colPos].getValue(),
2090420914
isLeftOfStartingCellEmpty = cells[colPos] ? !cells[colPos].getValue() : false,
2090520915
jumpCol = colPos,
20906-
nextCell = this.findJumpCell(cells.slice(0, colPos), true, isStartingCellEmpty, isLeftOfStartingCellEmpty);
20916+
targetCells = this.rowHeader ? cells.slice(1, colPos) : cells.slice(0, colPos),
20917+
nextCell = this.findJumpCell(targetCells, true, isStartingCellEmpty, isLeftOfStartingCellEmpty);
2090720918

2090820919
if(nextCell){
20909-
jumpCol = nextCell.column.getPosition() - 2;
20920+
jumpCol = nextCell.column.getPosition() - 1;
2091020921
}
2091120922

2091220923
return jumpCol;
@@ -20915,13 +20926,13 @@ class SelectRange extends Module {
2091520926
findJumpCellRight(rowPos, colPos){
2091620927
var row = this.getRowByRangePos(rowPos),
2091720928
cells = row.cells.filter((cell) => cell.column.visible),
20918-
isStartingCellEmpty = !cells[colPos + 1].getValue(),
20919-
isRightOfStartingCellEmpty = cells[colPos + 2] ? !cells[colPos + 2].getValue() : false,
20929+
isStartingCellEmpty = !cells[colPos].getValue(),
20930+
isRightOfStartingCellEmpty = cells[colPos + 1] ? !cells[colPos + 1].getValue() : false,
2092020931
jumpCol = colPos,
20921-
nextCell = this.findJumpCell(cells.slice(colPos + 2, cells.length), false, isStartingCellEmpty, isRightOfStartingCellEmpty);
20932+
nextCell = this.findJumpCell(cells.slice(colPos + 1, cells.length), false, isStartingCellEmpty, isRightOfStartingCellEmpty);
2092220933

2092320934
if(nextCell){
20924-
jumpCol = nextCell.column.getPosition() - 2;
20935+
jumpCol = nextCell.column.getPosition() - 1;
2092520936
}
2092620937

2092720938
return jumpCol;
@@ -20972,8 +20983,13 @@ class SelectRange extends Module {
2097220983
range = this.resetRanges();
2097320984
this.selecting = "all";
2097420985

20975-
const topLeftCell = this.getCell(0, 0);
20976-
const bottomRightCell = this.getCell(-1, -1);
20986+
var topLeftCell, bottomRightCell = this.getCell(-1, -1);
20987+
20988+
if(this.rowHeader){
20989+
topLeftCell = this.getCell(0, 1);
20990+
}else {
20991+
topLeftCell = this.getCell(0, 0);
20992+
}
2097720993

2097820994
range.setBounds(topLeftCell, bottomRightCell);
2097920995
return;
@@ -20997,16 +21013,19 @@ class SelectRange extends Module {
2099721013

2099821014
autoScroll(range, row, column) {
2099921015
var tableHolder = this.table.rowManager.element,
21000-
rowHeader = this.rowHeader.getElement(),
21001-
rect, view, withinHorizontalView, withinVerticalView;
21002-
21016+
rowHeader, rect, view, withinHorizontalView, withinVerticalView;
21017+
2100321018
if (typeof row === 'undefined') {
2100421019
row = this.getRowByRangePos(range.end.row).getElement();
2100521020
}
2100621021

2100721022
if (typeof column === 'undefined') {
2100821023
column = this.getColumnByRangePos(range.end.col).getElement();
2100921024
}
21025+
21026+
if (this.rowHeader) {
21027+
rowHeader = this.rowHeader.getElement();
21028+
}
2101021029

2101121030
rect = {
2101221031
left: column.offsetLeft,
@@ -21016,19 +21035,26 @@ class SelectRange extends Module {
2101621035
};
2101721036

2101821037
view = {
21019-
left: tableHolder.scrollLeft + rowHeader.offsetWidth,
21038+
left: tableHolder.scrollLeft,
2102021039
right: Math.ceil(tableHolder.scrollLeft + tableHolder.clientWidth),
2102121040
top: tableHolder.scrollTop,
2102221041
bottom: tableHolder.scrollTop + tableHolder.offsetHeight - this.table.rowManager.scrollbarWidth,
2102321042
};
21043+
21044+
if (rowHeader) {
21045+
view.left += rowHeader.offsetWidth;
21046+
}
2102421047

2102521048
withinHorizontalView = view.left < rect.left && rect.left < view.right && view.left < rect.right && rect.right < view.right;
2102621049

2102721050
withinVerticalView = view.top < rect.top && rect.top < view.bottom && view.top < rect.bottom && rect.bottom < view.bottom;
2102821051

2102921052
if (!withinHorizontalView) {
2103021053
if (rect.left < view.left) {
21031-
tableHolder.scrollLeft = rect.left - rowHeader.offsetWidth;
21054+
tableHolder.scrollLeft = rect.left;
21055+
if (rowHeader) {
21056+
tableHolder.scrollLeft -= rowHeader.offsetWidth;
21057+
}
2103221058
} else if (rect.right > view.right) {
2103321059
tableHolder.scrollLeft = rect.right - tableHolder.clientWidth;
2103421060
}
@@ -21147,8 +21173,7 @@ class SelectRange extends Module {
2114721173
var row;
2114821174

2114921175
if (colIdx < 0) {
21150-
colIdx = this.getTableColumns().length + colIdx - 1;
21151-
21176+
colIdx = this.getTableColumns().length + colIdx;
2115221177
if (colIdx < 0) {
2115321178
return null;
2115421179
}
@@ -21160,7 +21185,7 @@ class SelectRange extends Module {
2116021185

2116121186
row = this.table.rowManager.getRowFromPosition(rowIdx + 1);
2116221187

21163-
return row ? row.getCells(false, true).filter((cell) => cell.column.visible)[colIdx + 1] : null;
21188+
return row ? row.getCells(false, true).filter((cell) => cell.column.visible)[colIdx] : null;
2116421189
}
2116521190

2116621191

@@ -21173,7 +21198,7 @@ class SelectRange extends Module {
2117321198
}
2117421199

2117521200
getColumnByRangePos(pos) {
21176-
return this.getTableColumns()[pos + 1];
21201+
return this.getTableColumns()[pos];
2117721202
}
2117821203

2117921204
getTableRows() {

dist/js/tabulator_esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/modules/Edit/defaults/editors/datetime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function(cell, onRendered, success, cancel, editorParams){
3737
newDatetime = DT.fromFormat(String(cellValue), inputFormat);
3838
}
3939

40-
cellValue = newDatetime.toFormat("yyyy-MM-dd") + "T" + newDatetime.toFormat("hh:mm");
40+
cellValue = newDatetime.toFormat("yyyy-MM-dd") + "T" + newDatetime.toFormat("HH:mm");
4141
}else{
4242
console.error("Editor Error - 'date' editor 'format' param is dependant on luxon.js");
4343
}

src/js/modules/Edit/defaults/editors/time.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ export default function(cell, onRendered, success, cancel, editorParams){
3737
newDatetime = DT.fromFormat(String(cellValue), inputFormat);
3838
}
3939

40-
cellValue = newDatetime.toFormat("hh:mm");
40+
cellValue = newDatetime.toFormat("HH:mm");
4141

4242
}else{
4343
console.error("Editor Error - 'date' editor 'format' param is dependant on luxon.js");
4444
}
4545
}
46+
47+
console.log("val", cellValue)
4648

4749
input.value = cellValue;
4850

0 commit comments

Comments
 (0)