diff --git a/packages/components/src/components/data-grid/data-grid.tsx b/packages/components/src/components/data-grid/data-grid.tsx index d5c16bf9ee..6480bb4534 100644 --- a/packages/components/src/components/data-grid/data-grid.tsx +++ b/packages/components/src/components/data-grid/data-grid.tsx @@ -105,7 +105,7 @@ export class DataGrid { @Prop() shadeAlternate?: boolean = true; /** (optional) Injected css styles */ @Prop() styles: any; - /** (optional) Set to falseto hide table, used for nested tables to re-render upon toggle */ + /** (optional) Set to false to hide table, used for nested tables to re-render upon toggle */ @Prop() visible?: boolean = true; /* 4. Events (alphabetical) */ @@ -720,6 +720,20 @@ export class DataGrid { this.elTableHead.style.transform = `translateY(${scrollY}px)`; } + handleMenuListClick = (event) => { + const menuItems = ['sortBy', 'toggleVisibility']; + const currentMenuItemsIndex = menuItems.indexOf(event.target.id); + if (currentMenuItemsIndex > -1) { + // check if there is already opened flyout menu list with different id, if opened, close it + const inactiveMenuItem = this.hostElement.shadowRoot.querySelector( + `#${menuItems[1 - currentMenuItemsIndex]}List` + ) as HTMLUListElement; + if (inactiveMenuItem) { + inactiveMenuItem.setAttribute('opened', 'false'); + } + } + }; + renderSettingsMenu() { return ( @@ -733,10 +747,13 @@ export class DataGrid { {this.isSortable && ( - + Sort By - + {this.fields.map( ( { label, type, sortable, sortDirection = 'none' }, @@ -782,10 +799,17 @@ export class DataGrid { )} - + Toggle Visibility - + {this.fields.map( ( { diff --git a/packages/components/src/components/data-grid/readme.md b/packages/components/src/components/data-grid/readme.md index 88e6767232..88d286ace2 100644 --- a/packages/components/src/components/data-grid/readme.md +++ b/packages/components/src/components/data-grid/readme.md @@ -1,7 +1,5 @@ # scale-data-grid - - @@ -24,7 +22,7 @@ | `selection` | -- | Read-only selection array - populated with raw data from selected rows | `string[]` | `[]` | | `shadeAlternate` | `shade-alternate` | (optional) Shade every second row darker | `boolean` | `true` | | `styles` | `styles` | (optional) Injected css styles | `any` | `undefined` | -| `visible` | `visible` | (optional) Set to falseto hide table, used for nested tables to re-render upon toggle | `boolean` | `true` | +| `visible` | `visible` | (optional) Set to false to hide table, used for nested tables to re-render upon toggle | `boolean` | `true` | ## Events