React 계층형 그리드 셀 선택
React 계층적 그리드의 Ignite UI for React 셀 선택은 풍부한 데이터 선택 기능을 가능하게 하고 강력한 API를 제공합니다. IgrHierarchicalGrid
구성 요소. React Hierarchical Grid는 세 가지 선택 모드를 지원합니다.
계층적 그리드(Hierarchical Grid) 다중 셀 선택
계층적 그리드 단일 선택
계층적 그리드 없음 선택
IgrHierarchicalGrid
에서 그리드 수준에서 셀 선택 모드를 지정할 수 있습니다. 예를 들어 부모 그리드에서는 다중 셀 선택을 활성화할 수 있지만 자식 그리드에서는 셀 선택 모드를 단일 또는 비활성화할 수 있습니다.
각 옵션에 대해 자세히 알아보겠습니다.
React 계층적 그리드 셀 선택 예제
아래 샘플은 세 가지 유형의 IgrHierarchicalGrid
셀 선택 동작을 보여줍니다. 아래 버튼을 사용하여 사용 가능한 각 선택 모드를 활성화하십시오. 스낵바 메시지 상자를 통한 각 버튼 상호 작용에 대한 간략한 설명이 제공됩니다.
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrPropertyEditorPanelModule } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrPropertyEditorPanel, IgrPropertyEditorPropertyDescription } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebHierarchicalGridDescriptionModule } from "@infragistics/igniteui-react-core" ;
import SingersData from './SingersData.json' ;
import { IgrPropertyEditorPropertyDescriptionChangedEventArgs } from "@infragistics/igniteui-react-layouts" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
const mods : any [] = [
IgrPropertyEditorPanelModule,
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private propertyEditorHierarchicalGrid: IgrPropertyEditorPanel
private propertyEditorHierarchicalGridRef(r: IgrPropertyEditorPanel) {
this .propertyEditorHierarchicalGrid = r;
this .setState({});
}
private cellSelectionEditorHierarchicalGrid: IgrPropertyEditorPropertyDescription
private cellSelectionEditorRowIsland: IgrPropertyEditorPropertyDescription
private hierarchicalGrid: IgrHierarchicalGrid
private hierarchicalGridRef(r: IgrHierarchicalGrid) {
this .hierarchicalGrid = r;
this .setState({});
}
private rowIsland: IgrRowIsland
constructor (props: any ) {
super (props);
this .propertyEditorHierarchicalGridRef = this .propertyEditorHierarchicalGridRef.bind(this );
this .webRowIslandCellSelectionChange = this .webRowIslandCellSelectionChange.bind(this );
this .hierarchicalGridRef = this .hierarchicalGridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="options vertical" >
<IgrPropertyEditorPanel
ref ={this.propertyEditorHierarchicalGridRef}
componentRenderer ={this.renderer}
target ={this.hierarchicalGrid}
descriptionType ="WebHierarchicalGrid"
isHorizontal ="true"
isWrappingEnabled ="true" >
<IgrPropertyEditorPropertyDescription
label ="Hierarchical Grid Cell Selection"
propertyPath ="CellSelection"
name ="CellSelectionEditorHierarchicalGrid"
valueType ="EnumValue" >
</IgrPropertyEditorPropertyDescription >
<IgrPropertyEditorPropertyDescription
label ="Row Island Cell Selection"
propertyPath =""
name ="CellSelectionEditorRowIsland"
valueType ="EnumValue"
dropDownNames ={[ "None ", "Single ", "Multiple ", "MultipleCascade "]}
dropDownValues ={[ "None ", "Single ", "Multiple ", "MultipleCascade "]}
changed ={this.webRowIslandCellSelectionChange} >
</IgrPropertyEditorPropertyDescription >
</IgrPropertyEditorPanel >
</div >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ={false}
data ={this.singersData}
primaryKey ="ID"
id ="hierarchicalGrid"
ref ={this.hierarchicalGridRef} >
<IgrColumn
field ="Artist"
header ="Artist"
dataType ="string" >
</IgrColumn >
<IgrColumn
field ="HasGrammyAward"
header ="Has Grammy Award"
dataType ="boolean" >
</IgrColumn >
<IgrColumn
field ="Debut"
header ="Debut"
dataType ="number" >
</IgrColumn >
<IgrColumn
field ="GrammyNominations"
header ="Grammy Nominations"
dataType ="number"
hasSummary ={true} >
</IgrColumn >
<IgrColumn
field ="GrammyAwards"
header ="Grammy Awards"
dataType ="number"
hasSummary ={true} >
</IgrColumn >
<IgrRowIsland
childDataKey ="Albums"
autoGenerate ={false} >
<IgrColumn
field ="Album"
header ="Album"
dataType ="string" >
</IgrColumn >
<IgrColumn
field ="LaunchDate"
header ="Launch Date"
dataType ="date" >
</IgrColumn >
<IgrColumn
field ="BillboardReview"
header ="Billboard Review"
dataType ="string" >
</IgrColumn >
<IgrColumn
field ="USBillboard200"
header ="US Billboard 200"
dataType ="string" >
</IgrColumn >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _singersData: any [] = SingersData;
public get singersData(): any [] {
return this ._singersData;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer(): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebHierarchicalGridDescriptionModule.register(context);
}
return this ._componentRenderer;
}
public webRowIslandCellSelectionChange(sender: any , args: IgrPropertyEditorPropertyDescriptionChangedEventArgs): void {
const rowIsland = document.getElementsByTagName("igc-row-island" )[0 ] as IgrRowIsland;
rowIsland.cellSelection = args.newValue.toLocaleLowerCase();
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
선택 유형
계층적 그리드(Hierarchical Grid) 다중 셀 선택
이는 부모 및 자식 그리드 모두의 기본 셀 선택 모드입니다. 한 번에 하나의 그리드에서 셀을 선택할 수 있으며 교차 그리드 범위를 선택하거나 선택한 셀을 여러 그리드에 둘 수 없습니다. 범위 선택 및 마우스 끌기 기능과 관련된 각 키 조합은 동일한 그리드에서만 사용할 수 있습니다.
셀을 선택하는 방법:
마우스 드래그 - 셀의 직사각형 데이터 선택이 수행됩니다.
By CTRL key press + Mouse drag - Multiple range selections would be performed. Any other existing cell selection will be persisted.
Instant multi-cell selection by using SHIFT key. Select single cell and select another single cell by holding the SHIFT key. Cell range between the two cells will be selected. Keep in mind that if another second cell is selected while holding SHIFT key the cell selection range will be updated based on the first selected cell position (starting point).
Keyboard multi-cell selection by using the Arrow keys while holding SHIFT key. Multi-cell selection range will be created based on the focused cell.
Keyboard multi-cell selection by using the CTRL + ↑ ↓ ← → keys and CTRL + HOME /END while holding SHIFT key. Multi-cell selection range will be created based on the focused cell.
Clicking with the Left Mouse key while holding CTRL key will add single cell ranges into the selected cells collection.
마우스로 클릭하고 드래그하면 연속적인 다중 셀 선택이 가능합니다.
계층적 그리드 단일 선택
cellSelection
Single 로 설정하면 그리드에서 한 번에 하나의 셀만 선택할 수 있습니다. 또한 모드 마우스 끌기는 작동하지 않으며 셀을 선택하는 대신 기본 텍스트 선택이 됩니다.
단일 셀을 선택한 경우 selected
이벤트가 발생합니다. 선택 모드 ~이다 하나의 또는 다수의 . 다중 셀 선택 모드에서 셀 범위를 선택할 때 RangeSelected
이벤트가 방출됩니다.
계층적 그리드 없음 선택
셀 선택을 비활성화하려면 cellSelection
none 으로 설정하면 됩니다. 이 모드에서 셀을 클릭하거나 키보드로 탐색하려고 하면 셀이 선택되지 않고 활성화 스타일 만 적용되며 페이지의 다른 요소를 스크롤하거나 클릭하면 셀이 손실됩니다. 선택을 정의하는 유일한 방법은 아래에 설명된 API 메서드를 사용하는 것입니다.
키보드 탐색 상호 작용
Shift 키를 누르고 있는 동안
SHIFT + ↑ to add above cell to the current selection.
SHIFT + ↓ to add below cell to the current selection.
SHIFT + ← to add left cell to the current selection.
SHIFT + → to add right cell to the current selection.
Ctrl + Shift 키를 누르고 있는 동안
CTRL + SHIFT + ↑ to select all cells above the focused cell in the column.
CTRL + SHIFT + ↓ to select all cells below the focused cell in the column.
CTRL + SHIFT + ← to select all cells till the start of the row.
CTRL + SHIFT + → to select all cells till the end of the row.
CTRL + SHIFT + HOME to select all cells from the focused cell till the first-most cell in the grid
CTRL + SHIFT + END to select all cells from the focused cell till the last-most cell in the grid
연속스크롤은 Grid의 Body 내에서만 가능합니다.
API 사용법
다음은 범위를 선택하거나, 선택 항목을 지우거나, 선택한 셀 데이터를 가져오는 데 사용할 수 있는 방법입니다.
범위 선택
selectRange
- API를 사용하여 셀 범위를 선택합니다. rowStart 및 rowEnd는 행 인덱스를 사용해야 하고, columnStart 및 columnEnd는 열 인덱스 또는 열 데이터 필드 값을 사용할 수 있습니다.
const range : IgrGridSelectionRange [] = [{ rowStart: 2 , rowEnd: 2 , columnStart: "ProductName" , columnEnd: "UnitsInStock" }];
gridRef.current.selectRange(range)
tsx
셀 선택 지우기
clearCellSelection
현재 셀 선택을 지웁니다.
gridRef.current.clearCellSelection();
tsx
선택한 데이터 가져오기
getSelectedData
선택 항목에 따라 선택한 데이터의 배열을 형식으로 반환합니다. 아래 예:
expectedData = [
{ CompanyName : 'Infragistics' },
{ Name : 'Michael Langdon' },
{ ParentID : 147 }
];
typescript
expectedData = [
{ Address : 'Obere Str. 57' },
{ Address : 'Avda. de la Constitución 2222' },
{ Address : 'Mataderos 2312' }
];
typescript
행 1개, 열 3개에서 마우스 드래그로 셀 3개를 선택한 경우:
expectedData = [
{ Address : 'Avda. de la Constitución 2222' , City : 'México D.F.' , ContactTitle : 'Owner' }
];
typescript
2개의 행과 3개의 열에서 마우스 드래그로 3개의 셀을 선택한 경우:
expectedData = [
{ ContactTitle : 'Sales Agent' , Address : 'Cerrito 333' , City : 'Buenos Aires' },
{ ContactTitle : 'Marketing Manager' , Address : 'Sierras de Granada 9993' , City : 'México D.F.' }
];
typescript
expectedData = [
{ ContactName : 'Martín Sommer' , ContactTitle : 'Owner' },
{ ContactName : 'Laurence Lebihan' , ContactTitle : 'Owner' },
{ Address : '23 Tsawassen Blvd.' , City : 'Tsawassen' },
{ Address : 'Fauntleroy Circus' , City : 'London' }
];
typescript
두 개의 겹치는 범위를 선택한 경우 형식은 다음과 같습니다.
expectedData = [
{ ContactName : 'Diego Roel' , ContactTitle : 'Accounting Manager' , Address : 'C/ Moralzarzal, 86' },
{ ContactName : 'Martine Rancé' , ContactTitle : 'Assistant Sales Agent' , Address : '184, chaussée de Tournai' , City : 'Lille' },
{ ContactName : 'Maria Larsson' , ContactTitle : 'Owner' , Address : 'Åkergatan 24' , City : 'Bräcke' },
{ ContactTitle : 'Marketing Manager' , Address : 'Berliner Platz 43' , City : 'München' }
];
typescript
기능 통합
다중 셀 선택은 인덱스 기반입니다(DOM 요소 선택).
Sorting
- 정렬이 수행되면 선택이 지워지지 않습니다. 오름차순 또는 내림차순으로 정렬하는 동안 현재 선택된 셀은 동일하게 유지됩니다.
Paging
- 페이징 시 선택한 셀이 지워집니다. 선택 항목은 여러 페이지에 걸쳐 유지되지 않습니다.
Filtering
- 필터링이 수행되면 선택이 지워지지 않습니다. 필터링이 지워지면 처음에 선택한 셀이 반환됩니다.
Resizing
- 열 크기 조정 시 선택한 셀이 지워지지 않습니다.
Hiding
- 선택한 셀을 지우지 않습니다. 열이 숨겨져 있으면 표시되는 다음 열의 셀이 선택됩니다.
pinning
- 선택한 셀이 지워지지 않습니다. 숨기는 것도 마찬가지
GroupBy
- 열 그룹화 시 선택한 셀이 지워지지 않습니다.
스타일링
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<IgrHierarchicalGrid className ="hGrid" > </IgrHierarchicalGrid >
tsx
그런 다음 해당 클래스에 대한 관련 CSS 속성을 설정합니다.
.hGrid {
--ig-grid-cell-selected-text-color : #fff ;
--ig-grid-cell-active-border-color : #f2c43c ;
--ig-grid-cell-selected-background : #0062a3 ;
--ig-grid-cell-editing-background : #0062a3 ;
}
css
데모
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrPropertyEditorPanelModule } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrPropertyEditorPanel, IgrPropertyEditorPropertyDescription } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebHierarchicalGridDescriptionModule } from "@infragistics/igniteui-react-core" ;
import SingersData from './SingersData.json' ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
const mods : any [] = [
IgrPropertyEditorPanelModule,
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private propertyEditor: IgrPropertyEditorPanel
private propertyEditorRef(r: IgrPropertyEditorPanel) {
this .propertyEditor = r;
this .setState({});
}
private cellSelectionEditor: IgrPropertyEditorPropertyDescription
private hGrid: IgrHierarchicalGrid
private hGridRef(r: IgrHierarchicalGrid) {
this .hGrid = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .propertyEditorRef = this .propertyEditorRef.bind(this );
this .hGridRef = this .hGridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="options vertical" >
<IgrPropertyEditorPanel
ref ={this.propertyEditorRef}
componentRenderer ={this.renderer}
target ={this.hGrid}
descriptionType ="WebHierarchicalGrid"
isHorizontal ="true"
isWrappingEnabled ="true" >
<IgrPropertyEditorPropertyDescription
propertyPath ="CellSelection"
name ="CellSelectionEditor"
valueType ="EnumValue"
dropDownNames ={[ "None ", "Single ", "Multiple "]}
dropDownValues ={[ "None ", "Single ", "Multiple "]}>
</IgrPropertyEditorPropertyDescription >
</IgrPropertyEditorPanel >
</div >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ={false}
data ={this.singersData}
id ="hGrid"
ref ={this.hGridRef}
primaryKey ="ID" >
<IgrColumn
field ="Artist"
header ="Artist"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Photo"
header ="Photo"
dataType ="image"
minWidth ="115px"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Debut"
header ="Debut"
dataType ="number"
minWidth ="88px"
maxWidth ="230px"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="GrammyNominations"
header ="Grammy Nominations"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="GrammyAwards"
header ="Grammy Awards"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrRowIsland
childDataKey ="Albums"
autoGenerate ={false} >
<IgrColumn
field ="Album"
header ="Album"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="LaunchDate"
header ="Launch Date"
dataType ="date"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="BillboardReview"
header ="Billboard Review"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="USBillboard200"
header ="US Billboard 200"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrRowIsland
childDataKey ="Songs"
autoGenerate ={false} >
<IgrColumn
field ="Number"
header ="No."
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Title"
header ="Title"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Released"
header ="Released"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Genre"
header ="Genre"
dataType ="string"
resizable ={true} >
</IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
<IgrRowIsland
childDataKey ="Tours"
autoGenerate ={false} >
<IgrColumn
field ="Tour"
header ="Tour"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="StartedOn"
header ="Started on"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Location"
header ="Location"
dataType ="string"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Headliner"
header ="Headliner"
dataType ="string"
resizable ={true} >
</IgrColumn >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _singersData: any [] = SingersData;
public get singersData(): any [] {
return this ._singersData;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer(): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebHierarchicalGridDescriptionModule.register(context);
}
return this ._componentRenderer;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
#hGrid {
--ig-grid-cell-selected-text-color : #FFFFFF ;
--ig-grid-cell-active-border-color : #f2c43c ;
--ig-grid-cell-selected-background : #0062a3 ;
}
css コピー
API 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.