From 305c31146cbeac6285e92df419ea5a7e9eb6ba51 Mon Sep 17 00:00:00 2001 From: Konstantin Dikov Date: Tue, 23 Jan 2024 20:34:48 +0200 Subject: [PATCH] docs(grid): Updating custom expand-collapse cell KB --- .../custom-expand-collapse-column.md | 17 ++-- .../custom-expand-collapse-column/main.jsx | 85 +++++++++++++++++++ 2 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 knowledge-base/examples/grid/custom-expand-collapse-column/main.jsx diff --git a/knowledge-base/custom-expand-collapse-column.md b/knowledge-base/custom-expand-collapse-column.md index fde3d7f9..92fb7b52 100644 --- a/knowledge-base/custom-expand-collapse-column.md +++ b/knowledge-base/custom-expand-collapse-column.md @@ -30,11 +30,16 @@ How can I have control over the expand/collapse column of the KendoReact Grid an To modify the expand/collapse column of the Grid: -1. Create a custom column that is bound to the expanded field. -1. Show the icons conditionally. +1. Remove the onExpandChange event handler from the Grid +1. Create a custom column that is bound to a custom expand field (different from the expandField set to the Grid). +1. Show the icons conditionally within the custom cell. +1. On click of the icons, trigger the onChange from the cell props, which will trigger the onItemChange event of the Grid +1. Within the onItemChange of the Grid, when the field is the custom expand field, change the expanded field state -For more information, refer to the following props: -* [`cell`]({% slug api_grid_gridcolumnprops %}#toc-cell) -* [`headerCell`]({% slug api_grid_gridcolumnprops %}#toc-headercell) -For the full implementation of the suggested approach, refer to the [demo on creating a custom expand/collapse column in the KendoReact Grid](https://stackblitz.com/edit/react-abh1id-pwtfuf?file=app/main.jsx). +Following is an example demonstrating this approach: + +{% meta id height:540 %} +{% embed_file grid/custom-expand-collapse-column/main.jsx preview %} +{% embed_file shared/products.json %} +{% endmeta %} diff --git a/knowledge-base/examples/grid/custom-expand-collapse-column/main.jsx b/knowledge-base/examples/grid/custom-expand-collapse-column/main.jsx new file mode 100644 index 00000000..fae88b3e --- /dev/null +++ b/knowledge-base/examples/grid/custom-expand-collapse-column/main.jsx @@ -0,0 +1,85 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { Grid, GridColumn as Column } from '@progress/kendo-react-grid'; +import products from './products.json'; +import { IconWrap } from '@progress/kendo-react-common'; +import { minusIcon, plusIcon } from '@progress/kendo-svg-icons'; +const DetailComponent = (props) => { + const dataItem = props.dataItem; + return ( +

+ In Stock: {dataItem.UnitsInStock} units +

+ ); +}; + +const expandCell = (props) => { + console.log(props); + return ( + + { + e.preventDefault(); + if (props.onChange) { + props.onChange({ + dataItem: props.dataItem, + dataIndex: props.dataIndex, + syntheticEvent: e, + field: 'expanded_custom', + value: !props.dataItem['expanded'], + }); + } + }} + href="#" + tabIndex={-1} + > + + + + ); +}; +const App = () => { + const [data, setData] = React.useState(products); + const onItemChange = (event) => { + //This is for the expand only + if (event.field == 'expanded_custom') { + let newData = data.map((item) => { + if (item.ProductID === event.dataItem.ProductID) { + item.expanded = !event.dataItem.expanded; + } + + return item; + }); + setData(newData); + } + + //Add standard onItemChange here + }; + return ( + + + + + + + + ); +}; +ReactDOM.render(, document.querySelector('my-app'));