forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow swapping handsontable with AG Grid Community in Rule Builder.
- Loading branch information
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<script lang="ts" setup> | ||
import { type ColDef, type GridApi, type ColumnApi, type GridReadyEvent, type ValueGetterParams, type IHeaderParams, type Column } from "ag-grid-community"; | ||
import { computed, ref , nextTick, watch } from "vue"; | ||
import { useAgGrid } from "@/composables/useAgGrid" | ||
import { type SampleSheetColumnDefinition, type SampleSheetColumnDefinitions } from "@/api"; | ||
import { useResizeObserver } from "@vueuse/core"; | ||
interface Props { | ||
data: string[][]; | ||
colHeaders: string[]; | ||
height?: string; | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
height: "500px", | ||
}); | ||
const agGrid = ref<HTMLDivElement | null>(null); | ||
useResizeObserver(agGrid, () => { | ||
resize(); | ||
}); | ||
// Default Column Properties | ||
const defaultColDef = ref<ColDef>({ | ||
editable: false, | ||
sortable: false, | ||
filter: false, | ||
resizable: false, // maybe should be true? | ||
suppressMovable: true, | ||
}); | ||
const style = computed(() => { | ||
return { width: "100%", height: props.height }; | ||
}); | ||
const agColumnHeaders = computed(() => { | ||
return props.colHeaders.map((header:string, index: number) => { | ||
return { | ||
headerName: header, | ||
headerComponent: CustomHeader, | ||
valueGetter: (params: ValueGetterParams) => { return params.data[index]; } }; | ||
}); | ||
}); | ||
class CustomHeader { | ||
private eGui: HTMLElement | undefined; | ||
init(params: IHeaderParams) { | ||
this.eGui = document.createElement('div'); | ||
this.eGui.style.cssText = "width: 100%; text-align: center"; | ||
this.eGui.innerHTML = `${params.displayName}`; | ||
} | ||
getGui() { | ||
return this.eGui!; | ||
} | ||
refresh(params: IHeaderParams): boolean { | ||
return false; | ||
} | ||
} | ||
defineExpose({ CustomHeader }); | ||
// this doesn't work but the idea is to increase the column widths to fill | ||
// the horizontal space if they are too small after auto-sizing. | ||
/* | ||
function cleanUpColumnsIfNeeded() { | ||
if(columnApi.value) { | ||
const gridWidth = document.querySelector("#rules-ag-grid")?.clientWidth || 0; | ||
const totalColumnWidth = (columnApi.value.getAllColumns() || []).reduce( | ||
(sum: number, col: Column) => sum + (col.getActualWidth() || 0), | ||
0 | ||
); | ||
if (totalColumnWidth < gridWidth && gridApi.value) { | ||
gridApi.value.sizeColumnsToFit(); | ||
} | ||
} | ||
} | ||
*/ | ||
function resize() { | ||
if(columnApi.value) { | ||
columnApi.value.autoSizeAllColumns(); | ||
} | ||
} | ||
const { columnApi, AgGridVue, onGridReady, resizeOnNextTick, theme } = useAgGrid(resize); | ||
watch(() => props.colHeaders, resizeOnNextTick); | ||
</script> | ||
|
||
<template> | ||
<div :class="theme" :style="style"> | ||
<AgGridVue | ||
ref="agGrid" | ||
id="rules-ag-grid" | ||
:rowData="data" | ||
:columnDefs="agColumnHeaders" | ||
:defaultColDef="defaultColDef" | ||
:style="style" | ||
:row-height="20" | ||
:header-height="30" | ||
:cell-selection="true" | ||
@gridReady="onGridReady" /> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
/* Reduce padding and font size for compact rows */ | ||
.ag-theme-alpine .ag-row { | ||
font-size: 12px; | ||
line-height: 20px; /* Adjust line height to match rowHeight */ | ||
padding: 2px 5px; /* Adjust padding */ | ||
} | ||
/* Adjust header font size and padding */ | ||
.ag-theme-alpine .ag-header-cell-label { | ||
font-size: 13px; | ||
padding: 3px 5px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type GridApi, type ColumnApi, type GridReadyEvent } from "ag-grid-community"; | ||
|
||
import "ag-grid-community/styles/ag-grid.min.css"; | ||
import "ag-grid-community/styles/ag-theme-alpine.min.css"; | ||
|
||
import { ref, nextTick, defineAsyncComponent } from "vue"; | ||
|
||
export function useAgGrid(forceGridSize: () => void) { | ||
const gridApi = ref<GridApi | null>(null); | ||
const columnApi = ref<ColumnApi | null>(null); | ||
const theme = "ag-theme-alpine"; | ||
function resizeOnNextTick() { | ||
nextTick(forceGridSize); | ||
} | ||
|
||
function onGridReady(params: GridReadyEvent) { | ||
gridApi.value = params.api; | ||
columnApi.value = params.columnApi; | ||
forceGridSize(); | ||
} | ||
|
||
const AgGridVue = defineAsyncComponent(async () => { | ||
const { AgGridVue } = await import(/* webpackChunkName: "agGrid" */ "ag-grid-vue"); | ||
return AgGridVue; | ||
}); | ||
|
||
return { AgGridVue, gridApi, columnApi, resizeOnNextTick, onGridReady, theme }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters