canvas-datagrid 0.3.22 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/canvas-datagrid.debug.js +2272 -157
- package/dist/canvas-datagrid.debug.map +1 -1
- package/dist/canvas-datagrid.js +1 -1
- package/dist/canvas-datagrid.module.js +1 -1
- package/dist/canvas-datagrid.module.js.map +1 -1
- package/dist/types.d.ts +114 -0
- package/lib/contextMenu.js +283 -0
- package/lib/defaults.js +35 -0
- package/lib/docs.js +18 -0
- package/lib/dom.js +27 -5
- package/lib/draw.js +626 -30
- package/lib/events/index.js +145 -50
- package/lib/events/util.js +6 -5
- package/lib/intf.js +584 -3
- package/lib/publicMethods.js +378 -12
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -74,6 +74,8 @@
|
|
|
74
74
|
* @param [args.blanksText = (Blanks)] - The text that appears on the context menu for filtering blank values (i.e. `undefined`, `null`, `''`).
|
|
75
75
|
* @param [args.ellipsisText = ...] - The text used as ellipsis text on truncated values.
|
|
76
76
|
* @param [args.allowSorting = true] - Allow user to sort rows by clicking on column headers.
|
|
77
|
+
* @param [args.allowGroupingColumns = true] - Allow user to group columns by clicking on column headers.
|
|
78
|
+
* @param [args.allowGroupingRows = true] - Allow user to group rows by clicking on rows headers.
|
|
77
79
|
* @param [args.showFilter = true] - When true, filter will be an option in the context menu.
|
|
78
80
|
* @param [args.pageUpDownOverlap = 1] - Amount of rows to overlap when pageup/pagedown is used.
|
|
79
81
|
* @param [args.persistantSelectionMode = false] - When true, selections will behave as if the command/control key is held down at all times. Conflicts with singleSelectionMode.
|
|
@@ -101,6 +103,18 @@
|
|
|
101
103
|
* @param [args.clearSettingsOptionText = 'Clear saved settings'] - Text that appears on the clear settings option.
|
|
102
104
|
* @param [args.showOrderByOptionTextDesc = 'Order by %s ascending'] - Text that appears on the order by descending option.
|
|
103
105
|
* @param [args.showOrderByOptionTextAsc = 'Order by %s desc'] - Text that appears on the order by ascending option.
|
|
106
|
+
* @param [args.showGroupColumns = 'Group columns %s'] - Text that appears on the group columns option.
|
|
107
|
+
* @param [args.showGroupRows = 'Group row %s'] - Text that appears on the group rows option.
|
|
108
|
+
* @param [args.showRemoveGroupColumns = 'Remove group %s'] - Text that appears on the remove columns group option.
|
|
109
|
+
* @param [args.showRemoveGroupRows = 'Remove group %s'] - Text that appears on the remove rows group option.
|
|
110
|
+
* @param [args.showRemoveAllGroupColumns = 'Remove all column groups'] - Text that appears on the remove all column groups option.
|
|
111
|
+
* @param [args.showRemoveAllGroupRows = 'Remove all row groups'] - Text that appears on the remove all row groups option.
|
|
112
|
+
* @param [args.showExpandAllGroupColumns = 'Expand all column groups'] - Text that appears on the expand all column groups option.
|
|
113
|
+
* @param [args.showExpandAllGroupRows = 'Expand all row groups'] - Text that appears on the expand all row groups option.
|
|
114
|
+
* @param [args.showCollapseAllGroupColumns = 'Collapse all column groups'] - Text that appears on the collapsed all column groups option.
|
|
115
|
+
* @param [args.showCollapseAllGroupRows = 'Collapse all row groups'] - Text that appears on the collapsed all row groups option.
|
|
116
|
+
* @param [args.columnGroupIndicatorPosition = 'right'] - The position of the column group inidcator(icon), available values: 'left' and 'right'.
|
|
117
|
+
* @param [args.rowGroupIndicatorPosition = 'bottom'] - Ths position of the row group indicator(icon), available values: 'top' and 'bottom'.
|
|
104
118
|
* @param [args.showOrderByOption = true] - Show an option on the context menu sort rows.
|
|
105
119
|
* @param [args.showPaste = false] - Show the paste option in the context menu when applicable.
|
|
106
120
|
* @param [args.schema = []] - Sets the schema. See {@link canvasDatagrid.schema}.
|
|
@@ -163,6 +177,8 @@ declare class canvasDatagrid {
|
|
|
163
177
|
blanksText?: string;
|
|
164
178
|
ellipsisText?: string;
|
|
165
179
|
allowSorting?: boolean;
|
|
180
|
+
allowGroupingColumns?: boolean;
|
|
181
|
+
allowGroupingRows?: boolean;
|
|
166
182
|
showFilter?: boolean;
|
|
167
183
|
pageUpDownOverlap?: number;
|
|
168
184
|
persistantSelectionMode?: boolean;
|
|
@@ -190,6 +206,18 @@ declare class canvasDatagrid {
|
|
|
190
206
|
clearSettingsOptionText?: string;
|
|
191
207
|
showOrderByOptionTextDesc?: string;
|
|
192
208
|
showOrderByOptionTextAsc?: string;
|
|
209
|
+
showGroupColumns?: string;
|
|
210
|
+
showGroupRows?: string;
|
|
211
|
+
showRemoveGroupColumns?: string;
|
|
212
|
+
showRemoveGroupRows?: string;
|
|
213
|
+
showRemoveAllGroupColumns?: string;
|
|
214
|
+
showRemoveAllGroupRows?: string;
|
|
215
|
+
showExpandAllGroupColumns?: string;
|
|
216
|
+
showExpandAllGroupRows?: string;
|
|
217
|
+
showCollapseAllGroupColumns?: string;
|
|
218
|
+
showCollapseAllGroupRows?: string;
|
|
219
|
+
columnGroupIndicatorPosition?: string;
|
|
220
|
+
rowGroupIndicatorPosition?: string;
|
|
193
221
|
showOrderByOption?: boolean;
|
|
194
222
|
showPaste?: boolean;
|
|
195
223
|
schema?: any[];
|
|
@@ -401,6 +429,16 @@ declare class canvasDatagrid {
|
|
|
401
429
|
* @param imgSrc - icon path to add into button.
|
|
402
430
|
*/
|
|
403
431
|
static addButton(columnIndex: number, rowIndex: number, offset: any, items: any, imgSrc: string): void;
|
|
432
|
+
/**
|
|
433
|
+
* Expand/Collapse CellTree.
|
|
434
|
+
* @param treeData - The array of cellTree to expand or collapse.
|
|
435
|
+
*/
|
|
436
|
+
static toggleCellCollapseTree(treeData: any[]): void;
|
|
437
|
+
/**
|
|
438
|
+
* Expand/Collapse CellTree.
|
|
439
|
+
* @param treeData - The array of cellTree to expand or collapse.
|
|
440
|
+
*/
|
|
441
|
+
static expandCollapseCellTree(treeData: any[]): void;
|
|
404
442
|
/**
|
|
405
443
|
* Scrolls the cell at cell x, row y into view if it is not already.
|
|
406
444
|
* @param x - The column index of the cell to scroll into view.
|
|
@@ -499,6 +537,42 @@ declare class canvasDatagrid {
|
|
|
499
537
|
* @param [dontSetStorageData] - Don't store this setting for future use.
|
|
500
538
|
*/
|
|
501
539
|
static order(columnName: number, direction: string, sortFunction?: (...params: any[]) => any, dontSetStorageData?: boolean): void;
|
|
540
|
+
/**
|
|
541
|
+
* Grouping columns
|
|
542
|
+
* @param firstColumnName - Name of the first column to be grouped.
|
|
543
|
+
* @param lastColumnName - Name of the last column to be grouped.
|
|
544
|
+
*/
|
|
545
|
+
static groupColumns(firstColumnName: number | string, lastColumnName: number | string): void;
|
|
546
|
+
/**
|
|
547
|
+
* Grouping columns
|
|
548
|
+
* @param rowIndexFrom - The row index which is the beginning of the group
|
|
549
|
+
* @param rowIndexTo - The row index which is the end of the group
|
|
550
|
+
*/
|
|
551
|
+
static groupRows(rowIndexFrom: number, rowIndexTo: number): void;
|
|
552
|
+
/**
|
|
553
|
+
* Remove grouping columns
|
|
554
|
+
* @param firstColumnName - Name of the first column to be grouped.
|
|
555
|
+
* @param lastColumnName - Name of the last column to be grouped.
|
|
556
|
+
*/
|
|
557
|
+
static removeGroupColumns(firstColumnName: number | string, lastColumnName: number | string): void;
|
|
558
|
+
/**
|
|
559
|
+
* Remove grouping columns
|
|
560
|
+
* @param rowIndexFrom - The row index which is the beginning of the group
|
|
561
|
+
* @param rowIndexTo - The row index which is the end of the group
|
|
562
|
+
*/
|
|
563
|
+
static removeGroupRows(rowIndexFrom: number, rowIndexTo: number): void;
|
|
564
|
+
/**
|
|
565
|
+
* Toggle(expand/collapsed) grouping columns
|
|
566
|
+
* @param firstColumnName - Name of the first column to be grouped.
|
|
567
|
+
* @param lastColumnName - Name of the last column to be grouped.
|
|
568
|
+
*/
|
|
569
|
+
static toggleGroupColumns(firstColumnName: number | string, lastColumnName: number | string): void;
|
|
570
|
+
/**
|
|
571
|
+
* Toggle(expand/collapsed) grouping rows
|
|
572
|
+
* @param rowIndexFrom - The row index which is the beginning of the group
|
|
573
|
+
* @param rowIndexTo - The row index which is the end of the group
|
|
574
|
+
*/
|
|
575
|
+
static toggleGroupRows(rowIndexFrom: number, rowIndexTo: number): void;
|
|
502
576
|
/**
|
|
503
577
|
* Moves the current selection relative to the its current position. Note: this method does not move the selected data, just the selection itself.
|
|
504
578
|
* @param offsetX - The number of columns to offset the selection.
|
|
@@ -517,6 +591,16 @@ declare class canvasDatagrid {
|
|
|
517
591
|
* @param y - The row index to start inserting the selection at.
|
|
518
592
|
*/
|
|
519
593
|
static moveTo(sel: any[], x: number, y: number): void;
|
|
594
|
+
/**
|
|
595
|
+
* Get the column group info given column belongs to
|
|
596
|
+
* @param columnIndex - Column index.
|
|
597
|
+
*/
|
|
598
|
+
static getGroupsColumnBelongsTo(columnIndex: number): { from: number; to: number; collapsed: boolean; }[];
|
|
599
|
+
/**
|
|
600
|
+
* Get the row group info given row belongs to
|
|
601
|
+
* @param rowIndex - Row index.
|
|
602
|
+
*/
|
|
603
|
+
static getGroupsRowBelongsTo(rowIndex: number): { from: number; to: number; collapsed: boolean; }[];
|
|
520
604
|
/**
|
|
521
605
|
* Checks if a given column is visible.
|
|
522
606
|
* @param columnIndex - Column index.
|
|
@@ -536,6 +620,16 @@ declare class canvasDatagrid {
|
|
|
536
620
|
* @returns cell at the selected location.
|
|
537
621
|
*/
|
|
538
622
|
static getVisibleCellByIndex(x: number, y: number): cell;
|
|
623
|
+
/**
|
|
624
|
+
* @param x - Number of pixels from the left.
|
|
625
|
+
* @param y - Number of pixels from the top.
|
|
626
|
+
*/
|
|
627
|
+
static getColumnGroupAt(x: number, y: number): void;
|
|
628
|
+
/**
|
|
629
|
+
* @param x - Number of pixels from the left.
|
|
630
|
+
* @param y - Number of pixels from the top.
|
|
631
|
+
*/
|
|
632
|
+
static getRowGroupAt(x: number, y: number): void;
|
|
539
633
|
/**
|
|
540
634
|
* Gets the cell at grid pixel coordinate x and y. Author's note. This function ties drawing and events together. This is a very complex function and is core to the component.
|
|
541
635
|
* @param x - Number of pixels from the left.
|
|
@@ -1108,6 +1202,7 @@ declare namespace canvasDatagrid {
|
|
|
1108
1202
|
* @property [childContextMenuMarginTop = 0] - Style of childContextMenuMarginTop.
|
|
1109
1203
|
* @property [childContextMenuArrowHTML = ►] - Style of childContextMenuArrowHTML.
|
|
1110
1204
|
* @property [childContextMenuArrowColor = rgba(43, 48, 43, 1)] - Style of childContextMenuArrowColor.
|
|
1205
|
+
* @property [columnGroupRowHeight = 25] - Style of columnGroupRowHeight.
|
|
1111
1206
|
* @property [contextMenuChildArrowFontSize = 12px] - Style of contextMenuChildArrowFontSize.
|
|
1112
1207
|
* @property [cellWidth = 250] - Style of cellWidth.
|
|
1113
1208
|
* @property [contextMenuBackground = rgba(240, 240, 240, 1)] - Style of contextMenuBackground.
|
|
@@ -1162,6 +1257,8 @@ declare namespace canvasDatagrid {
|
|
|
1162
1257
|
* @property [gridBackgroundColor = rgba(240, 240, 240, 1)] - Style of gridBackgroundColor.
|
|
1163
1258
|
* @property [gridBorderColor = rgba(202, 202, 202, 1)] - Style of gridBorderColor.
|
|
1164
1259
|
* @property [gridBorderWidth = 1] - Style of gridBorderWidth.
|
|
1260
|
+
* @property [groupIndicatorColor = rgba(155, 155, 155, 1)'] - Foreground color of the group indicator(icon).
|
|
1261
|
+
* @property [groupIndicatorBackgroundColor = rgba(255, 255, 255, 1)'] - Background color of the group indicator(icon).
|
|
1165
1262
|
* @property [columnHeaderCellCapBackgroundColor = rgba(240, 240, 240, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
1166
1263
|
* @property [columnHeaderCellCapBorderColor = rgba(172, 172, 172, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
1167
1264
|
* @property [columnHeaderCellCapBorderWidth = 1] - Style of columnHeaderCellBackgroundColor.
|
|
@@ -1196,6 +1293,7 @@ declare namespace canvasDatagrid {
|
|
|
1196
1293
|
* @property [reorderMarkerBorderWidth = 1.25] - Style of reorderMarkerBorderWidth.
|
|
1197
1294
|
* @property [reorderMarkerIndexBorderColor = rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
|
|
1198
1295
|
* @property [reorderMarkerIndexBorderWidth = 2.75] - Style of reorderMarkerIndexBorderWidth.
|
|
1296
|
+
* @property [rowGroupColumnWidth = 25] - Style of rowGroupColumnWidth.
|
|
1199
1297
|
* @property [rowHeaderCellBackgroundColor = rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
|
|
1200
1298
|
* @property [rowHeaderCellBorderColor = rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
|
|
1201
1299
|
* @property [rowHeaderCellBorderWidth = 0.25] - Style of rowHeaderCellBorderWidth.
|
|
@@ -1466,6 +1564,10 @@ declare namespace canvasDatagrid {
|
|
|
1466
1564
|
* Style of childContextMenuArrowColor.
|
|
1467
1565
|
*/
|
|
1468
1566
|
childContextMenuArrowColor?: string;
|
|
1567
|
+
/**
|
|
1568
|
+
* Style of columnGroupRowHeight.
|
|
1569
|
+
*/
|
|
1570
|
+
columnGroupRowHeight?: number;
|
|
1469
1571
|
/**
|
|
1470
1572
|
* Style of contextMenuChildArrowFontSize.
|
|
1471
1573
|
*/
|
|
@@ -1682,6 +1784,14 @@ declare namespace canvasDatagrid {
|
|
|
1682
1784
|
* Style of gridBorderWidth.
|
|
1683
1785
|
*/
|
|
1684
1786
|
gridBorderWidth?: number;
|
|
1787
|
+
/**
|
|
1788
|
+
* Foreground color of the group indicator(icon).
|
|
1789
|
+
*/
|
|
1790
|
+
groupIndicatorColor?: string;
|
|
1791
|
+
/**
|
|
1792
|
+
* Background color of the group indicator(icon).
|
|
1793
|
+
*/
|
|
1794
|
+
groupIndicatorBackgroundColor?: string;
|
|
1685
1795
|
/**
|
|
1686
1796
|
* Style of columnHeaderCellBackgroundColor.
|
|
1687
1797
|
*/
|
|
@@ -1818,6 +1928,10 @@ declare namespace canvasDatagrid {
|
|
|
1818
1928
|
* Style of reorderMarkerIndexBorderWidth.
|
|
1819
1929
|
*/
|
|
1820
1930
|
reorderMarkerIndexBorderWidth?: number;
|
|
1931
|
+
/**
|
|
1932
|
+
* Style of rowGroupColumnWidth.
|
|
1933
|
+
*/
|
|
1934
|
+
rowGroupColumnWidth?: number;
|
|
1821
1935
|
/**
|
|
1822
1936
|
* Style of rowHeaderCellBackgroundColor.
|
|
1823
1937
|
*/
|
package/lib/contextMenu.js
CHANGED
|
@@ -684,6 +684,241 @@ export default function (self) {
|
|
|
684
684
|
},
|
|
685
685
|
});
|
|
686
686
|
}
|
|
687
|
+
//#region group/ungroup columns
|
|
688
|
+
const groupAreaHeight = self.getColumnGroupAreaHeight();
|
|
689
|
+
const groupAreaWidth = self.getRowGroupAreaWidth();
|
|
690
|
+
const setCollapseStateForAllGroups = (allGroups, collapsed) => {
|
|
691
|
+
if (allGroups.length === 0) return;
|
|
692
|
+
for (let i = 0; i < allGroups.length; i++) {
|
|
693
|
+
const groups = allGroups[i];
|
|
694
|
+
for (let j = 0; j < groups.length; j++) {
|
|
695
|
+
const group = groups[j];
|
|
696
|
+
group.collapsed = collapsed;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
self.refresh();
|
|
700
|
+
};
|
|
701
|
+
if (e.pos && e.pos.y < groupAreaHeight) {
|
|
702
|
+
e.items.push({
|
|
703
|
+
title: self.attributes.showRemoveAllGroupColumns,
|
|
704
|
+
click: function (ev) {
|
|
705
|
+
ev.preventDefault();
|
|
706
|
+
self.groupedColumns = [];
|
|
707
|
+
self.refresh();
|
|
708
|
+
},
|
|
709
|
+
});
|
|
710
|
+
e.items.push({
|
|
711
|
+
title: self.attributes.showExpandAllGroupColumns,
|
|
712
|
+
click: function (ev) {
|
|
713
|
+
ev.preventDefault();
|
|
714
|
+
setCollapseStateForAllGroups(self.groupedColumns, false);
|
|
715
|
+
},
|
|
716
|
+
});
|
|
717
|
+
e.items.push({
|
|
718
|
+
title: self.attributes.showCollapseAllGroupColumns,
|
|
719
|
+
click: function (ev) {
|
|
720
|
+
ev.preventDefault();
|
|
721
|
+
setCollapseStateForAllGroups(self.groupedColumns, true);
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
if (e.pos && e.pos.x < groupAreaWidth) {
|
|
726
|
+
e.items.push({
|
|
727
|
+
title: self.attributes.showRemoveAllGroupRows,
|
|
728
|
+
click: function (ev) {
|
|
729
|
+
ev.preventDefault();
|
|
730
|
+
self.groupedRows = [];
|
|
731
|
+
self.refresh();
|
|
732
|
+
},
|
|
733
|
+
});
|
|
734
|
+
e.items.push({
|
|
735
|
+
title: self.attributes.showExpandAllGroupRows,
|
|
736
|
+
click: function (ev) {
|
|
737
|
+
ev.preventDefault();
|
|
738
|
+
setCollapseStateForAllGroups(self.groupedRows, false);
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
e.items.push({
|
|
742
|
+
title: self.attributes.showCollapseAllGroupRows,
|
|
743
|
+
click: function (ev) {
|
|
744
|
+
ev.preventDefault();
|
|
745
|
+
setCollapseStateForAllGroups(self.groupedRows, true);
|
|
746
|
+
},
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const canGroupByColumns =
|
|
751
|
+
self.attributes.allowGroupingColumns &&
|
|
752
|
+
e.cell.isColumnHeader &&
|
|
753
|
+
e.cell.header &&
|
|
754
|
+
e.cell.header.index > 0;
|
|
755
|
+
const canUngroupColumns =
|
|
756
|
+
self.attributes.allowGroupingColumns && e.cell.isColumnHeader;
|
|
757
|
+
const canGroupByRows =
|
|
758
|
+
self.attributes.allowGroupingRows && e.cell.isRowHeader && e.cell.header;
|
|
759
|
+
const canUngroupRows =
|
|
760
|
+
self.attributes.allowGroupingRows && e.cell.isRowHeader;
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* The value for storing the return value from `self.getSchema()`
|
|
764
|
+
* @type {any[]}
|
|
765
|
+
*/
|
|
766
|
+
let schema;
|
|
767
|
+
/**
|
|
768
|
+
* A map between columnIndex and column data
|
|
769
|
+
* @type {Map<string,any>}
|
|
770
|
+
*/
|
|
771
|
+
let columns;
|
|
772
|
+
const getColumnsMap = () => {
|
|
773
|
+
if (!columns) {
|
|
774
|
+
if (!schema) schema = self.getSchema();
|
|
775
|
+
columns = new Map(schema.map((_col) => [_col.columnIndex, _col]));
|
|
776
|
+
}
|
|
777
|
+
return columns;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
if (canGroupByColumns) {
|
|
781
|
+
/** @type {number[]} */
|
|
782
|
+
const groupIndexes = [];
|
|
783
|
+
/** @type {number} */
|
|
784
|
+
const headerIndex = e.cell.header.index;
|
|
785
|
+
let col = headerIndex;
|
|
786
|
+
for (; col >= 0; col--) {
|
|
787
|
+
if (!self.isColumnSelected(col)) break;
|
|
788
|
+
groupIndexes[0] = col;
|
|
789
|
+
}
|
|
790
|
+
for (col = headerIndex; ; col++) {
|
|
791
|
+
if (!self.isColumnSelected(col)) break;
|
|
792
|
+
groupIndexes[1] = col;
|
|
793
|
+
}
|
|
794
|
+
if (
|
|
795
|
+
col !== headerIndex &&
|
|
796
|
+
groupIndexes.length === 2 &&
|
|
797
|
+
groupIndexes[1] > groupIndexes[0] &&
|
|
798
|
+
self.isNewGroupRangeValid(
|
|
799
|
+
self.groupedColumns,
|
|
800
|
+
groupIndexes[0],
|
|
801
|
+
groupIndexes[1],
|
|
802
|
+
)
|
|
803
|
+
) {
|
|
804
|
+
const columns = getColumnsMap();
|
|
805
|
+
const groupTitles = [];
|
|
806
|
+
const groupNames = [];
|
|
807
|
+
for (let i = 0; i < groupIndexes.length; i++) {
|
|
808
|
+
const columnIndex = groupIndexes[i];
|
|
809
|
+
const column = columns.get(columnIndex);
|
|
810
|
+
if (column) {
|
|
811
|
+
groupNames.push(column.name);
|
|
812
|
+
groupTitles.push(column.title || column.name || column.index);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (groupNames[0] && groupNames[1]) {
|
|
816
|
+
// show group options
|
|
817
|
+
e.items.push({
|
|
818
|
+
title: self.attributes.showGroupColumns.replace(
|
|
819
|
+
'%s',
|
|
820
|
+
groupTitles[0] + '-' + groupTitles[1],
|
|
821
|
+
),
|
|
822
|
+
click: function (ev) {
|
|
823
|
+
ev.preventDefault();
|
|
824
|
+
self.groupColumns(groupNames[0], groupNames[1]);
|
|
825
|
+
self.controlInput.focus();
|
|
826
|
+
},
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (canUngroupColumns) {
|
|
832
|
+
const columnIndex = e.cell.columnIndex;
|
|
833
|
+
const groups = self.getGroupsColumnBelongsTo(columnIndex);
|
|
834
|
+
const columns = getColumnsMap();
|
|
835
|
+
for (let i = 0; i < groups.length; i++) {
|
|
836
|
+
const { from, to } = groups[i];
|
|
837
|
+
const cell0 = columns.get(from);
|
|
838
|
+
const cell1 = columns.get(to);
|
|
839
|
+
if (cell0 && cell1) {
|
|
840
|
+
const formatArgs =
|
|
841
|
+
(cell0.title || cell0.name || cell0.index) +
|
|
842
|
+
'-' +
|
|
843
|
+
(cell1.title || cell1.name || cell1.index);
|
|
844
|
+
e.items.push({
|
|
845
|
+
title: self.attributes.showRemoveGroupColumns.replace(
|
|
846
|
+
'%s',
|
|
847
|
+
formatArgs,
|
|
848
|
+
),
|
|
849
|
+
click: function (ev) {
|
|
850
|
+
ev.preventDefault();
|
|
851
|
+
self.removeGroupColumns(cell0.name, cell1.name);
|
|
852
|
+
self.controlInput.focus();
|
|
853
|
+
},
|
|
854
|
+
});
|
|
855
|
+
} else {
|
|
856
|
+
console.warn(`Cannot find column ${from} or column ${to}`);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (canGroupByRows) {
|
|
861
|
+
let range = [];
|
|
862
|
+
let prev = -2;
|
|
863
|
+
let ok = true;
|
|
864
|
+
self.selections.forEach(function (row, index) {
|
|
865
|
+
if (!ok) return;
|
|
866
|
+
if (prev < -1) {
|
|
867
|
+
prev = index;
|
|
868
|
+
range[0] = index;
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if (index !== prev + 1 || !row || row.length === 0) {
|
|
872
|
+
ok = false;
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
prev = index;
|
|
876
|
+
range[1] = index;
|
|
877
|
+
});
|
|
878
|
+
const rangeTitle = range
|
|
879
|
+
.map((rowIndex) => {
|
|
880
|
+
const index = self.getBoundRowIndexFromViewRowIndex(rowIndex);
|
|
881
|
+
if (typeof index === 'number') return index + 1;
|
|
882
|
+
return rowIndex + 1;
|
|
883
|
+
})
|
|
884
|
+
.join('-');
|
|
885
|
+
if (
|
|
886
|
+
ok &&
|
|
887
|
+
range.length === 2 &&
|
|
888
|
+
self.isNewGroupRangeValid(self.groupedRows, range[0], range[1])
|
|
889
|
+
) {
|
|
890
|
+
e.items.push({
|
|
891
|
+
title: self.attributes.showGroupRows.replace('%s', rangeTitle),
|
|
892
|
+
click: function (ev) {
|
|
893
|
+
ev.preventDefault();
|
|
894
|
+
self.groupRows(range[0], range[1]);
|
|
895
|
+
},
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (canUngroupRows) {
|
|
900
|
+
const rowIndex = e.cell.rowIndex;
|
|
901
|
+
const groups = self.getGroupsRowBelongsTo(rowIndex);
|
|
902
|
+
for (let i = 0; i < groups.length; i++) {
|
|
903
|
+
const { from, to } = groups[i];
|
|
904
|
+
const rangeTitle = [from, to]
|
|
905
|
+
.map((rowIndex) => {
|
|
906
|
+
const index = self.getBoundRowIndexFromViewRowIndex(rowIndex);
|
|
907
|
+
if (typeof index === 'number') return index + 1;
|
|
908
|
+
return rowIndex + 1;
|
|
909
|
+
})
|
|
910
|
+
.join('-');
|
|
911
|
+
e.items.push({
|
|
912
|
+
title: self.attributes.showRemoveGroupRows.replace('%s', rangeTitle),
|
|
913
|
+
click: function (ev) {
|
|
914
|
+
ev.preventDefault();
|
|
915
|
+
self.removeGroupRows(from, to);
|
|
916
|
+
self.controlInput.focus();
|
|
917
|
+
},
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
//#endregion group/ungroup columns
|
|
687
922
|
}
|
|
688
923
|
self.disposeAutocomplete = function () {
|
|
689
924
|
if (autoCompleteContext) {
|
|
@@ -709,6 +944,53 @@ export default function (self) {
|
|
|
709
944
|
if (!self.hasFocus && e.target !== self.canvas) {
|
|
710
945
|
return;
|
|
711
946
|
}
|
|
947
|
+
// don't create context menu for parents if current position is located in child grid
|
|
948
|
+
const children = Object.keys(self.childGrids);
|
|
949
|
+
for (let i = 0; i < children.length; i++) {
|
|
950
|
+
const childGrid = self.childGrids[children[i]];
|
|
951
|
+
const parentNode = childGrid && childGrid.parentNode;
|
|
952
|
+
if (!parentNode) continue;
|
|
953
|
+
const { offsetLeft, offsetWidth, offsetTop, offsetHeight } = parentNode;
|
|
954
|
+
if ((e.x >= offsetLeft && e.x <= offsetLeft + offsetWidth) === false)
|
|
955
|
+
continue;
|
|
956
|
+
if ((e.y >= offsetTop && e.y <= offsetTop + offsetHeight) === false)
|
|
957
|
+
continue;
|
|
958
|
+
return; // in child grid
|
|
959
|
+
}
|
|
960
|
+
// don't create context menu for child if current position is located in parent grid
|
|
961
|
+
if (self.isChildGrid && self.parentNode) {
|
|
962
|
+
//#region check is current child grid closed
|
|
963
|
+
const childGridsOfParent = self.parentGrid && self.parentGrid.childGrids;
|
|
964
|
+
if (!childGridsOfParent || !Array.isArray(childGridsOfParent)) return;
|
|
965
|
+
const matchedMe = childGridsOfParent.find((grid) => {
|
|
966
|
+
const nodeA = grid.parentNode;
|
|
967
|
+
const nodeB = self.parentNode;
|
|
968
|
+
return (
|
|
969
|
+
nodeA.offsetTop == nodeB.offsetTop &&
|
|
970
|
+
nodeA.offsetLeft === nodeB.offsetLeft
|
|
971
|
+
);
|
|
972
|
+
});
|
|
973
|
+
if (!matchedMe) return;
|
|
974
|
+
//#endregion
|
|
975
|
+
|
|
976
|
+
let x0 = self.parentNode.offsetLeft;
|
|
977
|
+
let x1 = self.parentNode.offsetLeft + self.parentNode.offsetWidth;
|
|
978
|
+
let y0 = self.parentNode.offsetTop;
|
|
979
|
+
let y1 = self.parentNode.offsetTop + self.parentNode.offsetHeight;
|
|
980
|
+
let node = self.parentNode.parentNode;
|
|
981
|
+
while (node) {
|
|
982
|
+
const { offsetLeft, offsetWidth, offsetTop, offsetHeight } = node;
|
|
983
|
+
if (offsetLeft > x0) x0 = offsetLeft;
|
|
984
|
+
if (offsetTop > y0) y0 = offsetTop;
|
|
985
|
+
const newX1 = offsetLeft + offsetWidth;
|
|
986
|
+
const newY1 = offsetTop + offsetHeight;
|
|
987
|
+
if (newX1 < x1) x1 = newX1;
|
|
988
|
+
if (newY1 < y1) y1 = newY1;
|
|
989
|
+
if (node.nodeType !== 'canvas-datagrid-tree') break;
|
|
990
|
+
node = node.parentNode;
|
|
991
|
+
}
|
|
992
|
+
if ((e.x >= x0 && e.x <= x1 && e.y >= y0 && e.y <= y1) === false) return;
|
|
993
|
+
}
|
|
712
994
|
function createDisposeEvent() {
|
|
713
995
|
requestAnimationFrame(function () {
|
|
714
996
|
document.addEventListener('click', self.disposeContextMenu);
|
|
@@ -721,6 +1003,7 @@ export default function (self) {
|
|
|
721
1003
|
ev = {
|
|
722
1004
|
NativeEvent: e,
|
|
723
1005
|
cell: self.getCellAt(pos.x, pos.y),
|
|
1006
|
+
pos,
|
|
724
1007
|
items: items,
|
|
725
1008
|
};
|
|
726
1009
|
if (!ev.cell.isGrid) {
|
package/lib/defaults.js
CHANGED
|
@@ -16,6 +16,8 @@ export default function (self) {
|
|
|
16
16
|
['allowRowResize', true],
|
|
17
17
|
['allowRowResizeFromCell', false],
|
|
18
18
|
['allowSorting', true],
|
|
19
|
+
['allowGroupingRows', true],
|
|
20
|
+
['allowGroupingColumns', true],
|
|
19
21
|
['animationDurationShowContextMenu', 50],
|
|
20
22
|
['animationDurationHideContextMenu', 50],
|
|
21
23
|
['autoGenerateSchema', false],
|
|
@@ -74,6 +76,20 @@ export default function (self) {
|
|
|
74
76
|
['showOrderByOption', true],
|
|
75
77
|
['showOrderByOptionTextAsc', 'Order by %s ascending'],
|
|
76
78
|
['showOrderByOptionTextDesc', 'Order by %s descending'],
|
|
79
|
+
//#region grouping
|
|
80
|
+
['showGroupColumns', 'Group columns %s'],
|
|
81
|
+
['showGroupRows', 'Group rows %s'],
|
|
82
|
+
['showRemoveGroupColumns', 'Remove group %s'],
|
|
83
|
+
['showRemoveGroupRows', 'Remove group %s'],
|
|
84
|
+
['showRemoveAllGroupColumns', 'Remove all column groups'],
|
|
85
|
+
['showRemoveAllGroupRows', 'Remove all row groups'],
|
|
86
|
+
['showExpandAllGroupColumns', 'Expand all column groups'],
|
|
87
|
+
['showExpandAllGroupRows', 'Expand all row groups'],
|
|
88
|
+
['showCollapseAllGroupColumns', 'Collapse all column groups'],
|
|
89
|
+
['showCollapseAllGroupRows', 'Collapse all row groups'],
|
|
90
|
+
['columnGroupIndicatorPosition', 'right'],
|
|
91
|
+
['rowGroupIndicatorPosition', 'bottom'],
|
|
92
|
+
//#endregion grouping
|
|
77
93
|
['showPaste', false],
|
|
78
94
|
['showPerformance', false],
|
|
79
95
|
['showRowHeaders', true],
|
|
@@ -95,6 +111,11 @@ export default function (self) {
|
|
|
95
111
|
['maxPixelRatio', 2],
|
|
96
112
|
['tree', false],
|
|
97
113
|
['treeHorizontalScroll', false],
|
|
114
|
+
['rowTree', []],
|
|
115
|
+
['rowTreeColIndex', 0],
|
|
116
|
+
['columnTree', []],
|
|
117
|
+
['columnTreeRowStartIndex', 0],
|
|
118
|
+
['columnTreeRowEndIndex', 0],
|
|
98
119
|
],
|
|
99
120
|
styles: [
|
|
100
121
|
['activeCellBackgroundColor', 'rgba(255, 255, 255, 1)'],
|
|
@@ -149,6 +170,15 @@ export default function (self) {
|
|
|
149
170
|
['cellPaddingTop', 5],
|
|
150
171
|
['cellSelectedBackgroundColor', 'rgba(236, 243, 255, 1)'],
|
|
151
172
|
['cellSelectedColor', 'rgba(0, 0, 0, 1)'],
|
|
173
|
+
['cellTreeIconBorderColor', 'rgba(162, 174, 207, 1)'],
|
|
174
|
+
['cellTreeIconFillColor', 'rgba(240, 240, 240, 1)'],
|
|
175
|
+
['cellTreeIconHoverFillColor', 'rgba(198, 217, 233, 1)'],
|
|
176
|
+
['cellTreeIconLineColor', 'rgba(43, 53, 81, 1)'],
|
|
177
|
+
['cellTreeIconLineWidth', 1.5],
|
|
178
|
+
['cellTreeIconMarginLeft', 0],
|
|
179
|
+
['cellTreeIconMarginRight', 5],
|
|
180
|
+
['cellTreeIconMarginTop', 6],
|
|
181
|
+
['cellTreeIconWidth', 13],
|
|
152
182
|
['cellVerticalAlignment', 'center'],
|
|
153
183
|
['cellWidth', 250],
|
|
154
184
|
['cellWidthWithChildGrid', 250],
|
|
@@ -159,6 +189,7 @@ export default function (self) {
|
|
|
159
189
|
['childContextMenuArrowHTML', '►'],
|
|
160
190
|
['childContextMenuMarginLeft', -11],
|
|
161
191
|
['childContextMenuMarginTop', -6],
|
|
192
|
+
['columnGroupRowHeight', 25],
|
|
162
193
|
['columnHeaderCellBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
163
194
|
['columnHeaderCellBorderColor', 'rgba(172, 172, 172, 1)'],
|
|
164
195
|
['columnHeaderCellBorderWidth', 1],
|
|
@@ -267,10 +298,13 @@ export default function (self) {
|
|
|
267
298
|
['frozenMarkerBorderColor', 'rgba(168, 168, 168, 1)'],
|
|
268
299
|
['frozenMarkerBorderWidth', 1],
|
|
269
300
|
['frozenMarkerWidth', 2],
|
|
301
|
+
['groupingAreaBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
270
302
|
['gridBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
271
303
|
['gridBorderCollapse', 'collapse'],
|
|
272
304
|
['gridBorderColor', 'rgba(202, 202, 202, 1)'],
|
|
273
305
|
['gridBorderWidth', 1],
|
|
306
|
+
['groupIndicatorColor', 'rgba(155, 155, 155, 1)'],
|
|
307
|
+
['groupIndicatorBackgroundColor', 'rgba(255, 255, 255, 1)'],
|
|
274
308
|
['height', 'auto'],
|
|
275
309
|
['maxHeight', 'inherit'],
|
|
276
310
|
['maxWidth', 'inherit'],
|
|
@@ -293,6 +327,7 @@ export default function (self) {
|
|
|
293
327
|
['reorderMarkerBorderWidth', 1.25],
|
|
294
328
|
['reorderMarkerIndexBorderColor', 'rgba(66, 133, 244, 1)'],
|
|
295
329
|
['reorderMarkerIndexBorderWidth', 2.75],
|
|
330
|
+
['rowGroupColumnWidth', 25],
|
|
296
331
|
['rowHeaderCellBackgroundColor', 'rgba(240, 240, 240, 1)'],
|
|
297
332
|
['rowHeaderCellBorderColor', 'rgba(200, 200, 200, 1)'],
|
|
298
333
|
['rowHeaderCellBorderWidth', 1],
|
package/lib/docs.js
CHANGED
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
* @param {string} [args.blanksText=(Blanks)] - The text that appears on the context menu for filtering blank values (i.e. `undefined`, `null`, `''`).
|
|
38
38
|
* @param {string} [args.ellipsisText=...] - The text used as ellipsis text on truncated values.
|
|
39
39
|
* @param {boolean} [args.allowSorting=true] - Allow user to sort rows by clicking on column headers.
|
|
40
|
+
* @param {boolean} [args.allowGroupingColumns=true] - Allow user to group columns by clicking on column headers.
|
|
41
|
+
* @param {boolean} [args.allowGroupingRows=true] - Allow user to group rows by clicking on rows headers.
|
|
40
42
|
* @param {boolean} [args.showFilter=true] - When true, filter will be an option in the context menu.
|
|
41
43
|
* @param {number} [args.pageUpDownOverlap=1] - Amount of rows to overlap when pageup/pagedown is used.
|
|
42
44
|
* @param {boolean} [args.persistantSelectionMode=false] - When true, selections will behave as if the command/control key is held down at all times. Conflicts with singleSelectionMode.
|
|
@@ -64,6 +66,18 @@
|
|
|
64
66
|
* @param {string} [args.clearSettingsOptionText='Clear saved settings'] - Text that appears on the clear settings option.
|
|
65
67
|
* @param {string} [args.showOrderByOptionTextDesc='Order by %s ascending'] - Text that appears on the order by descending option.
|
|
66
68
|
* @param {string} [args.showOrderByOptionTextAsc='Order by %s desc'] - Text that appears on the order by ascending option.
|
|
69
|
+
* @param {string} [args.showGroupColumns='Group columns %s'] - Text that appears on the group columns option.
|
|
70
|
+
* @param {string} [args.showGroupRows='Group row %s'] - Text that appears on the group rows option.
|
|
71
|
+
* @param {string} [args.showRemoveGroupColumns='Remove group %s'] - Text that appears on the remove columns group option.
|
|
72
|
+
* @param {string} [args.showRemoveGroupRows='Remove group %s'] - Text that appears on the remove rows group option.
|
|
73
|
+
* @param {string} [args.showRemoveAllGroupColumns='Remove all column groups'] - Text that appears on the remove all column groups option.
|
|
74
|
+
* @param {string} [args.showRemoveAllGroupRows='Remove all row groups'] - Text that appears on the remove all row groups option.
|
|
75
|
+
* @param {string} [args.showExpandAllGroupColumns='Expand all column groups'] - Text that appears on the expand all column groups option.
|
|
76
|
+
* @param {string} [args.showExpandAllGroupRows='Expand all row groups'] - Text that appears on the expand all row groups option.
|
|
77
|
+
* @param {string} [args.showCollapseAllGroupColumns='Collapse all column groups'] - Text that appears on the collapsed all column groups option.
|
|
78
|
+
* @param {string} [args.showCollapseAllGroupRows='Collapse all row groups'] - Text that appears on the collapsed all row groups option.
|
|
79
|
+
* @param {string} [args.columnGroupIndicatorPosition='right'] - The position of the column group inidcator(icon), available values: 'left' and 'right'.
|
|
80
|
+
* @param {string} [args.rowGroupIndicatorPosition='bottom'] - Ths position of the row group indicator(icon), available values: 'top' and 'bottom'.
|
|
67
81
|
* @param {boolean} [args.showOrderByOption=true] - Show an option on the context menu sort rows.
|
|
68
82
|
* @param {boolean} [args.showPaste=false] - Show the paste option in the context menu when applicable.
|
|
69
83
|
* @param {array} [args.schema=[]] - Sets the schema. See {@link canvasDatagrid.schema}.
|
|
@@ -298,6 +312,7 @@
|
|
|
298
312
|
* @property {number} [childContextMenuMarginTop=0] - Style of childContextMenuMarginTop.
|
|
299
313
|
* @property {string} [childContextMenuArrowHTML=►] - Style of childContextMenuArrowHTML.
|
|
300
314
|
* @property {string} [childContextMenuArrowColor=rgba(43, 48, 43, 1)] - Style of childContextMenuArrowColor.
|
|
315
|
+
* @property {number} [columnGroupRowHeight=25] - Style of columnGroupRowHeight.
|
|
301
316
|
* @property {string} [contextMenuChildArrowFontSize=12px] - Style of contextMenuChildArrowFontSize.
|
|
302
317
|
* @property {number} [cellWidth=250] - Style of cellWidth.
|
|
303
318
|
* @property {string} [contextMenuBackground=rgba(240, 240, 240, 1)] - Style of contextMenuBackground.
|
|
@@ -352,6 +367,8 @@
|
|
|
352
367
|
* @property {string} [gridBackgroundColor=rgba(240, 240, 240, 1)] - Style of gridBackgroundColor.
|
|
353
368
|
* @property {string} [gridBorderColor=rgba(202, 202, 202, 1)] - Style of gridBorderColor.
|
|
354
369
|
* @property {number} [gridBorderWidth=1] - Style of gridBorderWidth.
|
|
370
|
+
* @property {string} [groupIndicatorColor=rgba(155, 155, 155, 1)'] - Foreground color of the group indicator(icon).
|
|
371
|
+
* @property {string} [groupIndicatorBackgroundColor=rgba(255, 255, 255, 1)'] - Background color of the group indicator(icon).
|
|
355
372
|
* @property {string} [columnHeaderCellCapBackgroundColor=rgba(240, 240, 240, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
356
373
|
* @property {string} [columnHeaderCellCapBorderColor=rgba(172, 172, 172, 1)] - Style of columnHeaderCellBackgroundColor.
|
|
357
374
|
* @property {number} [columnHeaderCellCapBorderWidth=1] - Style of columnHeaderCellBackgroundColor.
|
|
@@ -386,6 +403,7 @@
|
|
|
386
403
|
* @property {number} [reorderMarkerBorderWidth=1.25] - Style of reorderMarkerBorderWidth.
|
|
387
404
|
* @property {string} [reorderMarkerIndexBorderColor=rgba(66, 133, 244, 1)] - Style of reorderMarkerIndexBorderColor.
|
|
388
405
|
* @property {number} [reorderMarkerIndexBorderWidth=2.75] - Style of reorderMarkerIndexBorderWidth.
|
|
406
|
+
* @property {number} [rowGroupColumnWidth=25] - Style of rowGroupColumnWidth.
|
|
389
407
|
* @property {string} [rowHeaderCellBackgroundColor=rgba(240, 240, 240, 1)] - Style of rowHeaderCellBackgroundColor.
|
|
390
408
|
* @property {string} [rowHeaderCellBorderColor=rgba(152, 152, 152, 1)] - Style of rowHeaderCellBorderColor.
|
|
391
409
|
* @property {number} [rowHeaderCellBorderWidth=0.25] - Style of rowHeaderCellBorderWidth.
|