-
Notifications
You must be signed in to change notification settings - Fork 0
/
27_aggrid_picture.qmd
62 lines (48 loc) · 1.34 KB
/
27_aggrid_picture.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "AG Grid with Pictures"
format:
html:
theme: flatly
font: Georgia
self-contained: true
page-layout: custom
mode: visual
---
```{r include=F}
library(tidyverse)
df <- tibble(
product = c("ČISTIČ BRZD", "ČISTICÍ PAPÍR ECOLINE"),
picture = c(
"https://media.wuerth.com/source/eshop/stmedia/wuerth/images/std.lang.all/resolutions/category/576px/170494.jpg",
"https://media.wuerth.com/source/eshop/stmedia/wuerth/images/std.lang.all/resolutions/category/576px/42348.jpg"
),
value = c(200, 400)
)
ojs_define(df = df)
```
```{ojs}
//| echo: false
AgGrid = require('ag-grid-enterprise/dist/ag-grid-enterprise.js') // also the css in the YAML header!!!
picRenderer = params => `<img src="${params.value}" width="50" height="50">`;
html`<div id="myGrid" style="width: 20%;height:400px;" class="ag-theme-alpine"></div>`
gridOptions = {
const eGridDiv = document.getElementById('myGrid');
const columnDefs = [
{ field: 'product'},
{ field: 'picture', cellRenderer: picRenderer, maxWidth: "90" }
];
const gridOptions = {
columnDefs: columnDefs,
rowData: transpose(df),
rowSelection: 'single',
defaultColDef: {
flex: 1,
minWidth: 100,
resizable: true,
},
};
new AgGrid.Grid(eGridDiv, gridOptions);
gridOptions.api.sizeColumnsToFit();
return gridOptions;
}
```