Skip to content

Commit 6c8fd37

Browse files
committed
add kbs
1 parent 49cf7dd commit 6c8fd37

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
import {
4+
ExcelExport,
5+
ExcelExportColumn,
6+
WorkbookOptions,
7+
} from '@progress/kendo-react-excel-export';
8+
9+
import products from './products.json';
10+
11+
const data = products;
12+
const modifiedData = data.map((item) => ({
13+
...item,
14+
}));
15+
16+
const App = () => {
17+
const _exporter = React.createRef<ExcelExport>();
18+
const excelExport = () => {
19+
save(_exporter);
20+
};
21+
const save = (component) => {
22+
const options: WorkbookOptions = component.current.workbookOptions();
23+
const rows = options.sheets[0].rows;
24+
25+
const dataMap = new Map(modifiedData.map((item) => [item.ProductID, item]));
26+
27+
rows.forEach((row) => {
28+
if (row.type === 'data') {
29+
const productID = row.cells[0].value;
30+
const dataItem = dataMap.get(productID);
31+
32+
if (dataItem && dataItem.is_total) {
33+
row.cells.forEach((cell) => {
34+
cell.bold = true;
35+
});
36+
}
37+
}
38+
});
39+
40+
component.current.save(options);
41+
};
42+
return (
43+
<div>
44+
<button
45+
className="k-button k-button-md k-rounded-md k-button-solid k-button-solid-base"
46+
onClick={excelExport}
47+
>
48+
Export to Excel
49+
</button>
50+
51+
<ExcelExport data={modifiedData} fileName="Products.xlsx" ref={_exporter}>
52+
<ExcelExportColumn field="ProductID" title="Product ID" />
53+
<ExcelExportColumn field="ProductName" title="Product Name" />
54+
</ExcelExport>
55+
</div>
56+
);
57+
};
58+
59+
ReactDOM.render(<App />, document.querySelector('my-app'));
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import * as React from "react";
2+
import * as ReactDOM from "react-dom";
3+
import { TileLayout } from "@progress/kendo-react-layout";
4+
import { Grid } from "@progress/kendo-react-grid";
5+
import products from "./products.json";
6+
const initialDataState = {
7+
skip: 0,
8+
take: 10,
9+
};
10+
const App = () => {
11+
const [data, setData] = React.useState([
12+
{
13+
col: 1,
14+
colSpan: 3,
15+
rowSpan: 3,
16+
},
17+
]);
18+
19+
const rowHeight = 200;
20+
21+
const calculateRowSpan = (contentHeight) => {
22+
const minHeight = Math.max(contentHeight, rowHeight);
23+
return Math.ceil(minHeight / rowHeight);
24+
};
25+
26+
const adjustRowSpanBasedOnContent = () => {
27+
const gridElement = document.querySelector(".k-grid");
28+
const contentHeight = gridElement ? gridElement.clientHeight : 0;
29+
const newRowSpan = calculateRowSpan(contentHeight);
30+
31+
setData((prevData) =>
32+
prevData.map((item, index) =>
33+
index === 0 ? { ...item, rowSpan: newRowSpan } : item
34+
)
35+
);
36+
};
37+
38+
React.useEffect(() => {
39+
adjustRowSpanBasedOnContent();
40+
}, [products]);
41+
42+
const [page, setPage] = React.useState(initialDataState);
43+
const [pageSizeValue, setPageSizeValue] = React.useState();
44+
const pageChange = (event) => {
45+
const targetEvent = event.targetEvent;
46+
const take =
47+
targetEvent.value === "All" ? products.length : event.page.take;
48+
if (targetEvent.value) {
49+
setPageSizeValue(targetEvent.value);
50+
}
51+
setPage({
52+
...event.page,
53+
take,
54+
});
55+
};
56+
const tiles = [
57+
{
58+
header: "Page Views",
59+
body: (
60+
<Grid
61+
maxHeight={500}
62+
data={products.slice(page.skip, page.take + page.skip)}
63+
/>
64+
),
65+
},
66+
];
67+
const handleReposition = (e) => {
68+
setData(e.value);
69+
console.log(e.value);
70+
};
71+
return (
72+
<TileLayout
73+
columns={4}
74+
rowHeight={200}
75+
positions={data}
76+
gap={{
77+
rows: 10,
78+
columns: 10,
79+
}}
80+
items={tiles}
81+
onReposition={handleReposition}
82+
/>
83+
);
84+
};
85+
export default App;
86+
ReactDOM.render(<App />, document.querySelector("my-app"));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Conditional Cell Styling in ExcelExport
3+
description: This article provides guidance on how to apply conditional cell styling based on specific data conditions within the ExcelExport
4+
type: how-to
5+
page_title: Applying Conditional Cell Styling in the ExcelExport Component
6+
slug: excel-conditional-cell-styling
7+
tags: excel-export, conditional-styling, cell-formatting
8+
res_type: kb
9+
category: knowledge-base
10+
ticketid: 1633213
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product Version</td>
18+
<td>7.0.2</td>
19+
</tr>
20+
<tr>
21+
<td>Product</td>
22+
<td>Progress® KendoReact</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
I want to apply conditional cell styling in the ExcelExport component within my application. Specifically, I need to format cells as bold based on the presence of a `is_total` flag in the row data. However, the `is_total` flag should not be included in the exported Excel data.
30+
31+
## Solution
32+
33+
To achieve conditional cell styling in the ExcelExport, set a flag variable to the exported data and apply the required styles if the flag is set to `true`
34+
35+
{% meta id:index height:330 %}
36+
{% embed_file excel/excel-conditional-styling.jsx preview %}
37+
{% endmeta %}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Adapting rowSpan to Contents in TileLayout for React
3+
description: Learn how to dynamically adjust the rowSpan value in a TileLayout based on the contents' height.
4+
type: how-to
5+
page_title: Adapting rowSpan to Contents in TileLayout for React | KendoReact TileLayout
6+
slug: tilelayout-adapt-rowspan-content-dynamically
7+
tags: tilelayout, rowSpan, content, dynamic, dynamically
8+
res_type: kb
9+
---
10+
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product Version</td>
17+
<td>7.0.2</td>
18+
</tr>
19+
<tr>
20+
<td>Product</td>
21+
<td>Progress® KendoReact</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
26+
## Description
27+
I want to adapt the `rowSpan` value in a TileLayout based on the height of its contents. Currently, I have set the `colSpan` and `rowSpan` to a static number, but this results in white space when there is less data in the grid.
28+
29+
## Solution
30+
31+
To dynamically adjust the `rowSpan` value based on the content height, create a function that obtains the Grid height and recalculates it based on your needs.
32+
33+
34+
{% meta id height:500 %}
35+
{% embed_file layout/tilelayout-adapt-rowspan-content-dynamically/main.jsx preview %}
36+
{% endmeta %}

0 commit comments

Comments
 (0)