React 계층형 그리드 열 크기 조정 개요
React Hierarchical Grid의 Ignite UI for React 사용하면 사용자가 IgrHierarchicalGrid
의 열 너비를 쉽게 조정할 수 있습니다. 기본적으로 드래그 크기 조정 작업이 진행되는 동안 임시 크기 조정 표시기가 표시됩니다. 사용 가능한 크기 조정 옵션은 여러 가지가 있습니다. 픽셀/백분율로 열 크기 조정, 열 크기 조정 제한, 더블 클릭 시 열 크기 자동 조정, 초기화 시 열 크기 자동 조정.
React Hierarchical Grid Column Resizing Example
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import SingersData from './SingersData.json' ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private hierarchicalGrid: IgrHierarchicalGrid
private hierarchicalGridRef(r: IgrHierarchicalGrid) {
this .hierarchicalGrid = r;
this .setState({});
}
private column: IgrColumn
private rowIsland: IgrRowIsland
constructor (props: any ) {
super (props);
this .hierarchicalGridRef = this .hierarchicalGridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ={false}
data ={this.singersData}
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 ="date"
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;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
Like this sample? Get access to our complete Ignite UI for React toolkit and start building your own apps in minutes. Download it for free.
열 크기 조정 은 열 수준별로 사용하도록 설정되며, 이는 크기 조정이 IgrHierarchicalGrid
가능한 열과 크기 조정이 불가능한 열을 혼합할 수 있음을 의미합니다. 이것은 의 IgrColumn
입력을 resizable
통해 수행됩니다.
<IgrColumn field ="Artist" resizable ={true} > </IgrColumn >
tsx
를 구독할 수 있습니다. ColumnResized
의 이벤트 IgrHierarchicalGrid
열의 크기가 조정될 때 일부 사용자 지정 논리를 구현합니다. 이전 및 새 열 너비와 함께 IgrColumn
객체는 이벤트 인수를 통해 노출됩니다.
const onResize = (event: IgrColumnResizeEventArgs) => {
const col = event.detail.column;
const pWidth = event.detail.prevWidth;
const nWidth = event.detail.newWidth;
}
<IgrHierarchicalGrid id ="hierarchicalGrid" autoGenerate ={false} onColumnResized ={onResize} >
<IgrColumn field ="Artist" resizable ={true} > </IgrColumn >
</IgrHierarchicalGrid >
tsx
Resizing Columns in Pixels/Percentages
사용자 시나리오에 따라 열 너비는 픽셀, 백분율 또는 두 가지의 혼합으로 정의될 수 있습니다. 이러한 모든 시나리오는 열 크기 조정 기능으로 지원됩니다. 기본적으로 열에 너비가 설정되지 않은 경우 너비가 픽셀 단위로 설정된 사용 가능한 공간에 맞춰집니다.
이는 다음 구성이 가능함을 의미합니다.
<IgrHierarchicalGrid id ="hierarchicalGrid" onColumnResized ={onResize} autoGenerate ={false}
height ="600px" width ="100%" >
<IgrColumn field ="Artist" resizable ={true} width ="10%" > </IgrColumn >
<IgrColumn field ="GrammyNominations" resizable ={true} width ="100px" > </IgrColumn >
<IgrColumn field ="GrammyAwards" resizable ={true} > </IgrColumn >
</IgrHierarchicalGrid >
tsx
There is a slight difference in the way resizing works for columns set in pixels and percentages.
픽셀
너비(픽셀)로 열 크기를 조정하는 작업은 열 크기에서 마우스 이동의 수평 크기를 직접 더하거나 빼는 방식으로 수행됩니다.
백분율
너비(%)로 열 크기를 조정할 때 마우스 이동의 수평 크기(픽셀)는 대략 그리드 너비에 대한 백분율 크기로 변환됩니다. 열은 계속 반응하며 향후 그리드 크기 조정은 여전히 열에 반영됩니다.
Restrict Column Resizing
허용되는 최소 및 최대 열 너비를 구성할 수도 있습니다. 이는 IgrColumn
의 minWidth
및 maxWidth
입력을 통해 수행됩니다. 이 경우 크기 조정 표시기 끌기 작업은 minWidth
및 maxWidth
로 정의된 경계 밖에서 열 크기를 조정할 수 없음을 사용자에게 알리기 위해 제한됩니다.
<IgrColumn field ="Artist" width ="100px" resizable ={true}
minWidth ="60px" maxWidth ="230px" > </IgrColumn >
tsx
최소 및 최대 열 너비 값 유형(픽셀 또는 백분율)을 혼합하는 것이 허용됩니다. 최소값과 최대값에 대해 설정된 값이 백분율로 설정되면 각 열 크기는 픽셀과 유사한 정확한 크기로 제한됩니다.
이는 다음과 같은 구성이 가능함을 의미합니다.
<IgrColumn field ="Artist" width ="100px" resizable ={true}
minWidth ="60px" maxWidth ="230px" > </IgrColumn >
tsx
또는
<IgrColumn field ="Artist" width ="100px" resizable ={true}
minWidth ="60px" maxWidth ="15%" > </IgrColumn >
tsx
Auto-Size Columns on Double Click
헤더의 오른쪽을 두 번 클릭하면 각 열의 크기가 자동으로 조정될 수 있습니다. 열의 크기는 헤더 자체를 포함하여 현재 표시되는 가장 긴 셀 값으로 조정됩니다. 이 동작은 기본적으로 활성화되어 있으며 추가 구성이 필요하지 않습니다. 그러나 해당 열에 maxWidth
설정되어 있고 새 너비가 해당 maxWidth
값을 초과하는 경우 열 크기가 자동으로 조정되지 않습니다. 이 경우 열은 미리 설정된 maxWidth
값에 따라 크기가 조정됩니다.
IgrColumn
에 노출된 자동 크기 autosize
방법을 사용하여 열의 크기를 동적으로 자동 조정할 수도 있습니다.
const column = grid.getColumnByName('Artist' );
column.autosize();
tsx
Auto-Size Columns on Initialization
너비를 '자동'으로 설정하여 초기화 시 각 width
크기가 자동으로 조정되도록 설정할 수 있습니다.
<IgrColumn width ='auto' >
tsx
열이 뷰에서 처음 초기화되면 너비가 표시되는 가장 긴 셀이나 머리글의 크기로 확인됩니다. 표시되는 행 외부에 있는 셀은 포함되지 않습니다.
이 접근 방식은 초기화 후 자동 크기 조정보다 성능이 더 최적화되어 있으며 특히 많은 수의 열 크기를 자동 조정해야 하는 경우에 권장됩니다.
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import HierarchicalCustomers from './HierarchicalCustomers.json' ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private hierarchicalGrid1: IgrHierarchicalGrid
private hierarchicalGrid1Ref(r: IgrHierarchicalGrid) {
this .hierarchicalGrid1 = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .hierarchicalGrid1Ref = this .hierarchicalGrid1Ref.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ={false}
data ={this.hierarchicalCustomers}
ref ={this.hierarchicalGrid1Ref} >
<IgrColumn
field ="CustomerID"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="CompanyName"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ContactName"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ContactTitle"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Address"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="City"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="PostalCode"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Country"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Phone"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Fax"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrRowIsland
childDataKey ="Orders"
autoGenerate ={false} >
<IgrColumn
field ="OrderID"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="EmployeeID"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="OrderDate"
width ="auto"
dataType ="date"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="RequiredDate"
width ="auto"
dataType ="date"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShippedDate"
width ="auto"
dataType ="date"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipVia"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Freight"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipName"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipAddress"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipCity"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipPostalCode"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="ShipCountry"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrRowIsland
childDataKey ="OrderDetails"
autoGenerate ={false} >
<IgrColumn
field ="ProductID"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="UnitPrice"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Quantity"
width ="auto"
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Discount"
width ="auto"
resizable ={true} >
</IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _hierarchicalCustomers: any [] = HierarchicalCustomers;
public get hierarchicalCustomers(): any [] {
return this ._hierarchicalCustomers;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
Styling
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 크기 조정 핸들의 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<IgrHierarchicalGrid className ="grid" > </IgrHierarchicalGrid >
tsx
그런 다음 해당 클래스에 대한 관련 CSS 속성을 설정합니다.
.grid {
--ig-grid-resize -line-color : #f35b04 ;
}
css
Demo
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import SingersData from './SingersData.json' ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this .grid = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ={false}
ref ={this.gridRef}
id ="grid"
data ={this.singersData}
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 ="date"
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;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
#grid {
--ig-grid-resize -line-color : #f35b04 ;
}
css コピー
API References
Additional Resources
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.