mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
add RMB context menu to tables to set top calc type
This commit is contained in:
@@ -207,8 +207,35 @@ function addTableElement(blenderId, csvData, filename) {
|
|||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
var containerHeight=$('.table-container').height();
|
// create right click context menu for choosing column top calculation
|
||||||
var h3Height=$('.table-container>h3').height();
|
function createColumnContextMenu(column) {
|
||||||
|
const field = column.field;
|
||||||
|
const calculations = ["sum", "avg", "max", "min"];
|
||||||
|
|
||||||
|
// label is the item label in the menu
|
||||||
|
// update column defination on clicking an item
|
||||||
|
// specifically the topCalc and pass calc type to the topCalcFormatter function
|
||||||
|
// uisng the topCalcFormatterParams field
|
||||||
|
return calculations.map((calc) => ({
|
||||||
|
label: `Show ${
|
||||||
|
calc.charAt(0).toUpperCase() + calc.slice(1)
|
||||||
|
} for ${field}`,
|
||||||
|
action: (e, cell) =>
|
||||||
|
cell
|
||||||
|
.getColumn()
|
||||||
|
.updateDefinition({ topCalc: calc, topCalcFormatterParams: calc }),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcFormatter(cell, formatterParams, onRendered) {
|
||||||
|
// formatterParams is anything in the topCalcFormatterParams field in the column definition
|
||||||
|
// so we pass the calculation type to display what the calculation type is
|
||||||
|
return `${formatterParams}: ${cell.getValue()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
var containerHeight = $(".table-container").height();
|
||||||
|
var h3Height = $(".table-container>h3").height();
|
||||||
|
|
||||||
var table = new Tabulator("#table-" + blenderId, {
|
var table = new Tabulator("#table-" + blenderId, {
|
||||||
placeholder: "No data to display",
|
placeholder: "No data to display",
|
||||||
resizableColumnGuide: true,
|
resizableColumnGuide: true,
|
||||||
@@ -222,14 +249,21 @@ function addTableElement(blenderId, csvData, filename) {
|
|||||||
movableColumns: true,
|
movableColumns: true,
|
||||||
// Our fields are never nested, and we use the "." character in queries
|
// Our fields are never nested, and we use the "." character in queries
|
||||||
nestedFieldSeparator: false,
|
nestedFieldSeparator: false,
|
||||||
|
// defines column defualts that are applied to all columns
|
||||||
|
columnDefaults: {
|
||||||
|
visible: true,
|
||||||
|
headerFilter: true,
|
||||||
|
topCalc: "sum",
|
||||||
|
topCalcFormatter: calcFormatter,
|
||||||
|
topCalcFormatterParams: "sum",
|
||||||
|
},
|
||||||
|
// defines a callback to edit the column definition generated by autoColumns
|
||||||
|
// that cannot be set as default
|
||||||
autoColumnsDefinitions: function (definitions) {
|
autoColumnsDefinitions: function (definitions) {
|
||||||
menu = createHeaderMenu(definitions, table);
|
headerMenu = createHeaderMenu(definitions, table);
|
||||||
definitions.forEach((column) => {
|
definitions.forEach((column) => {
|
||||||
column.visible = true;
|
column.headerMenu = headerMenu;
|
||||||
column.headerFilter = true;
|
column.contextMenu = createColumnContextMenu(column);
|
||||||
column.headerMenu = menu;
|
|
||||||
// TODO: more user control to choose function, style at bottomCalc
|
|
||||||
column.topCalc = 'sum';
|
|
||||||
});
|
});
|
||||||
return definitions;
|
return definitions;
|
||||||
},
|
},
|
||||||
@@ -239,7 +273,9 @@ function addTableElement(blenderId, csvData, filename) {
|
|||||||
.css("margin-left", "10px")
|
.css("margin-left", "10px")
|
||||||
.css("cursor", "pointer");
|
.css("cursor", "pointer");
|
||||||
tableTitle.append(downloadCsv);
|
tableTitle.append(downloadCsv);
|
||||||
downloadCsv.on('click', function() { table.download("csv", "data.csv"); })
|
downloadCsv.on("click", function () {
|
||||||
|
table.download("csv", "data.csv");
|
||||||
|
});
|
||||||
|
|
||||||
table.on("rowSelected", function (row) {
|
table.on("rowSelected", function (row) {
|
||||||
var index = row.getIndex(); // the guid of the object
|
var index = row.getIndex(); // the guid of the object
|
||||||
|
|||||||
Reference in New Issue
Block a user