이 컨트롤은 더 이상 사용되지 않고 그리드 구성 요소로 대체되었으므로 해당 컨트롤로 마이그레이션하는 것이 좋습니다. 새로운 기능은 제공되지 않으며 버그 수정은 우선순위에서 제외됩니다. 코드베이스를 Data Grid로 마이그레이션하는 데 도움이 필요하거나 질문이 있으면 지원팀에 문의하세요.
Web Components Grid Column Chooser 개요
Ignite UI for Web Components Data Grid는 다음을 통해 UI를 사용하여 열을 표시하고 숨기는 기능을 지원합니다. IgcDataGridToolbarComponent
component 또는 columnChooser
페이지의 아무 곳에나 배치할 수 있는 유연성을 제공하는 구성 요소입니다. 이 IsHidden
열의 속성을 사용하여 수동 열 생성을 위해 프로그래밍 방식으로 단일 열을 빠르게 숨기거나 표시할 수도 있으며, IsHidden
에 반영됩니다. columnChooser
구성 요소. 각 방법을 서로 바꿔 사용하여 열의 표시 상태를 변경할 수 있습니다.
Web Components 그리드 열 선택기 예제
import { IgcDataGridModule } from 'igniteui-webcomponents-grids' ;
import { IgcGridColumnOptionsModule } from 'igniteui-webcomponents-grids' ;
import { IgcDataGridComponent } from 'igniteui-webcomponents-grids' ;
import { ModuleManager } from 'igniteui-webcomponents-core' ;
import { IgcTextColumnComponent } from 'igniteui-webcomponents-grids' ;
import { IgcDataGridToolbarModule } from 'igniteui-webcomponents-grids' ;
import { IgcDataGridToolbarComponent } from 'igniteui-webcomponents-grids' ;
ModuleManager.register(
IgcDataGridModule,
IgcDataGridToolbarModule,
IgcGridColumnOptionsModule
);
export class DataGridColumnChooserToolbar {
private grid: IgcDataGridComponent;
private toolbar: IgcDataGridToolbarComponent;
private data: any [] = [];
constructor ( ) {
this .grid = document .getElementById('grid' ) as IgcDataGridComponent;
this .toolbar = document .getElementById('toolbar' ) as IgcDataGridToolbarComponent;
this .initData();
this .grid.dataSource = this .data;
this .toolbar.targetGrid = this .grid;
}
public initData ( ) {
const names: string [] = [
'Intel CPU' , 'AMD CPU' ,
'Intel Motherboard' , 'AMD Motherboard' , 'Nvidia Motherboard' ,
'Nvidia GPU' , 'Gigabyte GPU' , 'Asus GPU' , 'AMD GPU' , 'MSI GPU' ,
'Corsair Memory' , 'Patriot Memory' , 'Skill Memory' ,
'Samsung HDD' , 'WD HDD' , 'Seagate HDD' , 'Intel HDD' , 'Asus HDD' ,
'Samsung SSD' , 'WD SSD' , 'Seagate SSD' , 'Intel SSD' , 'Asus SSD' ,
'Samsung Monitor' , 'Asus Monitor' , 'LG Monitor' , 'HP Monitor' ];
const countries: string [] = ['USA' , 'UK' , 'France' , 'Canada' , 'Poland' ,
'Denmark' , 'Croatia' , 'Australia' , 'Seychelles' ,
'Sweden' , 'Germany' , 'Japan' , 'Ireland' ,
'Barbados' , 'Jamaica' , 'Cuba' , 'Spain' ];
const status: string [] = [ 'Packing' , 'Shipped' , 'Delivered' ]
const sales: any [] = [];
for (let i = 0 ; i < 200 ; i++) {
const price = this .getRandomNumber(10000 , 90000 ) / 100 ;
const items = this .getRandomNumber(4 , 30 );
const value = Math .round(price * items);
const margin = this .getRandomNumber(2 , 5 );
const profit = Math .round((price * margin / 100 ) * items);
const country = this .getRandomItem(countries);
sales.push({
Country : country,
CountryFlag : this .getFlagImage(country),
Margin : margin,
OrderDate : this .getRandomDate(),
OrderItems : items,
OrderValue : value,
ProductID : 1001 + i,
ProductName : this .getRandomItem(names),
ProductPrice : price,
Profit : Math .round(profit),
Status : this .getRandomItem(status),
});
}
this .data = sales;
}
public getFlagImage(countryName: string ): string {
return 'https://static.infragistics.com/xplatform/images/flags/' + countryName + '.png' ;
}
public getGenderImage(gender: string ): string {
return 'https://static.infragistics.com/xplatform/images/genders/' + gender.toLowerCase() + '.png' ;
}
public getPersonImage(personID: string ): string {
return 'https://static.infragistics.com/xplatform/people/' + personID + '.png' ;
}
public getRandomDate(): Date {
const today: Date = new Date ();
const year: number = today.getFullYear();
const month: number = this .getRandomNumber(0 , 8 );
const day: number = this .getRandomNumber(10 , 27 );
return new Date (year, month, day);
}
public getRandomNumber(min: number , max : number ): number {
return Math .round(min + Math .random() * (max - min));
}
public getRandomItem(array: any []): any {
const index = Math .round(this .getRandomNumber(0 , array.length - 1 ));
return array[index];
}
}
new DataGridColumnChooserToolbar();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > DataGridColumnChooserToolbar</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample" >
<igc-data-grid-toolbar
id ="toolbar"
toolbar-title ="Global Sales"
column-chooser ="true" >
</igc-data-grid-toolbar >
<igc-data-grid
id ="grid"
height ="calc(100% - 6rem)"
width ="100%"
corner-radius-top-left ="0"
corner-radius-top-right ="0"
is-column-options-enabled ="true"
auto-generate-columns ="false" >
<igc-text-column field ="ProductID" header-text ="ID" width ="*>90" horizontal-alignment ="center" > </igc-text-column >
<igc-image-column field ="CountryFlag" header-text ="Country" width ="*>115" content-opacity ="1" horizontal-alignment ="center"
padding-top ="5" padding-bottom ="5" > </igc-image-column >
<igc-text-column id ="productname" field ="ProductName" header-text ="Product" > </igc-text-column >
<igc-numeric-column field ="ProductPrice" header-text ="Price" width ="*>90" positive-prefix ="$" show-grouping-separator ="true" min-fraction-digits ="2" > </igc-numeric-column >
<igc-numeric-column field ="OrderItems" header-text ="Orders" width ="*>110" > </igc-numeric-column >
<igc-numeric-column field ="OrderValue" header-text ="Order Value" width ="*>135" positive-prefix ="$" show-grouping-separator ="true" > </igc-numeric-column >
<igc-date-time-column field ="OrderDate" header-text ="Order Date" width ="*>130" horizontal-alignment ="right" date-time-format ="DateShort" > </igc-date-time-column >
<igc-numeric-column field ="Margin" header-text ="Margin" width ="*>105" positive-suffix ="%" horizontal-alignment ="center" > </igc-numeric-column >
<igc-numeric-column field ="Profit" header-text ="Profit" width ="*>100" positive-prefix ="$" show-grouping-separator ="true" > </igc-numeric-column >
<igc-text-column field ="Status" header-text ="Status" width ="*>110" horizontal-alignment ="center" > </igc-text-column >
</igc-data-grid >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
이 샘플이 마음에 드시나요? 당사의 완전한 Ignite UI for Web Components 툴킷에 액세스하여 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.
열 선택기 UI는 그리드와 별도로 IgcDataGridToolbarComponent
구성 요소 내에서 액세스할 수 있습니다. 이를 위해 우리가 해야 할 일은 도구 모음의 columnChooser
속성을 true로 설정하는 것뿐입니다. 그러면 도구 모음에 IgcButtonComponent
가 표시되고, 클릭하면 열 선택기 UI가 표시됩니다. 이 버튼은 숨겨진 열의 합계도 표시합니다. 도구 모음이 생성되지 않은 경우 IgcColumnChooserComponent
속성을 활성화해도 효과가 없으며 버튼이 숨겨집니다.
그만큼 IgcDataGridToolbarComponent
도구 모음에 제목을 추가하는 등의 추가 속성을 제공합니다. toolbarTitle
속성, 텍스트 배치 IgcButtonComponent
설정하여 ColumnChooserText
속성을 설정하고 열 선택기 UI에 제목 헤더를 추가합니다. ColumnChooserTitle
.
열 선택기는 그리드의 columnHidingAnimationMode
및 columnShowingAnimationMode
속성을 설정하여 애니메이션으로 구성할 수 있습니다.
코드 조각
다음은 Web Components Data Grid에 대한 열 선택기 도구 모음 UI를 구현하는 방법을 보여줍니다.
<igc-dataGrid-toolbar
toolbar-title ="Grid Title"
column-chooser ="true"
column-chooser-text ="Columns"
column-chooser-title ="Column Chooser" >
</igc-dataGrid-toolbar >
<igc-data-grid
id ="grid"
height ="calc(100% - 40px)"
width ="100%"
auto-generate-columns ="false"
default-column-min-width ="120px"
scrollbar-style = "thin"
column-hiding-animation-mode ="SlideOver" >
</igc-data-grid >
html
import { IgcDataGrid } from 'igniteui-webcomponents-grids' ;
import { IgcDataGridToolbar } from 'igniteui-webcomponents-grids' ;
import { ColumnMovingAnimationMode } from 'igniteui-webcomponents-grids' ;
private grid: IgcDataGridComponent;
private toolbar: IgcDataGridToolbarComponent;
connectedCallback ( ) {
this .toolbar.targetGrid = this .grid;
let productNameColumn = document .getElementById("productname" ) as IgcTextColumnComponent;
productNameColumn.isHidden = true ;
this .toolbar.columnChooser = true ;
this .toolbar.toolbarTitle = "Grid Title" ;
this .toolbar.columnChooserText = "Choose Text" ;
this .toolbar.columnChooserTitle = "Choose Title Text" ;
this .grid.columnMovingAnimationMode = ColumnMovingAnimationMode.SlideOver;
}
ts
간단한 열 선택기
도구 모음 없이 IgcColumnChooserComponent
UI를 수동으로 표시하고 페이지의 원하는 위치에 배치한다고 가정해 보겠습니다. 이는 마크업에서 구성 요소의 인스턴스를 생성하기만 하면 쉽게 수행할 수 있습니다.
데모
EXAMPLE
TS
HTML
DataGridStyles.css
index.css
import './DataGridStyles.css' ;
import { IgcDataGridModule } from 'igniteui-webcomponents-grids' ;
import { IgcGridColumnOptionsModule } from 'igniteui-webcomponents-grids' ;
import { IgcDataGridComponent } from 'igniteui-webcomponents-grids' ;
import { ModuleManager } from 'igniteui-webcomponents-core' ;
import { IgcColumnChooserModule } from 'igniteui-webcomponents-grids' ;
import { IgcColumnChooserComponent } from 'igniteui-webcomponents-grids' ;
ModuleManager.register(
IgcDataGridModule,
IgcColumnChooserModule,
IgcGridColumnOptionsModule
);
export class DataGridColumnChooserPicker {
private grid: IgcDataGridComponent;
private columnChooser: IgcColumnChooserComponent;
private data: any [] = [];
constructor ( ) {
this .grid = document .getElementById('grid' ) as IgcDataGridComponent;
this .columnChooser = document .getElementById('columnUI' ) as IgcColumnChooserComponent;
this .initData();
this .grid.dataSource = this .data;
this .columnChooser.targetGrid = this .grid;
}
public initData ( ) {
const names: string [] = [
'Intel CPU' , 'AMD CPU' ,
'Intel Motherboard' , 'AMD Motherboard' , 'Nvidia Motherboard' ,
'Nvidia GPU' , 'Gigabyte GPU' , 'Asus GPU' , 'AMD GPU' , 'MSI GPU' ,
'Corsair Memory' , 'Patriot Memory' , 'Skill Memory' ,
'Samsung HDD' , 'WD HDD' , 'Seagate HDD' , 'Intel HDD' , 'Asus HDD' ,
'Samsung SSD' , 'WD SSD' , 'Seagate SSD' , 'Intel SSD' , 'Asus SSD' ,
'Samsung Monitor' , 'Asus Monitor' , 'LG Monitor' , 'HP Monitor' ];
const countries: string [] = ['USA' , 'UK' , 'France' , 'Canada' , 'Poland' ,
'Denmark' , 'Croatia' , 'Australia' , 'Seychelles' ,
'Sweden' , 'Germany' , 'Japan' , 'Ireland' ,
'Barbados' , 'Jamaica' , 'Cuba' , 'Spain' ];
const status: string [] = [ 'Packing' , 'Shipped' , 'Delivered' ]
const sales: any [] = [];
for (let i = 0 ; i < 200 ; i++) {
const price = this .getRandomNumber(10000 , 90000 ) / 100 ;
const items = this .getRandomNumber(4 , 30 );
const value = Math .round(price * items);
const margin = this .getRandomNumber(2 , 5 );
const profit = Math .round((price * margin / 100 ) * items);
const country = this .getRandomItem(countries);
sales.push({
Country : country,
CountryFlag : this .getFlagImage(country),
Margin : margin,
OrderDate : this .getRandomDate(),
OrderItems : items,
OrderValue : value,
ProductID : 1001 + i,
ProductName : this .getRandomItem(names),
ProductPrice : price,
Profit : Math .round(profit),
Status : this .getRandomItem(status),
});
}
this .data = sales;
}
public getFlagImage(countryName: string ): string {
return 'https://static.infragistics.com/xplatform/images/flags/' + countryName + '.png' ;
}
public getGenderImage(gender: string ): string {
return 'https://static.infragistics.com/xplatform/images/genders/' + gender.toLowerCase() + '.png' ;
}
public getPersonImage(personID: string ): string {
return 'https://static.infragistics.com/xplatform/people/' + personID + '.png' ;
}
public getRandomDate(): Date {
const today: Date = new Date ();
const year: number = today.getFullYear();
const month: number = this .getRandomNumber(0 , 8 );
const day: number = this .getRandomNumber(10 , 27 );
return new Date (year, month, day);
}
public getRandomNumber(min: number , max : number ): number {
return Math .round(min + Math .random() * (max - min));
}
public getRandomItem(array: any []): any {
const index = Math .round(this .getRandomNumber(0 , array.length - 1 ));
return array[index];
}
}
new DataGridColumnChooserPicker();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > DataGridColumnChooserPicker</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container horizontal" >
<div class ="container" style ="margin-left: 0.4rem; margin-top: 2px; margin-right: 0.5rem; margin-bottom: 0.25rem; padding: 0.5rem; background: rgb(248, 248, 248); border-radius: 10px; box-shadow: 1px 1px 2px 2px rgb(50 50 50 / 25%)" >
<igc-column-chooser
id ="columnUI"
height ="100%"
width ="200px"
title ="Column Chooser"
show-all-text ="Show All"
hide-all-text ="Hide All" >
</igc-column-chooser >
</div >
<div class ="container" >
<igc-data-grid
id ="grid"
height ="100%"
width ="100%"
is-column-options-enabled ="true"
auto-generate-columns ="false" >
<igc-text-column field ="ProductID" header-text ="Product ID" width ="*>125" horizontal-alignment ="center" is-hidden ="true" > </igc-text-column >
<igc-image-column field ="CountryFlag" header-text ="Country" width ="*>115" content-opacity ="1" horizontal-alignment ="center"
padding-top ="5" padding-bottom ="5" > </igc-image-column >
<igc-text-column field ="ProductName" header-text ="Product" is-hidden ="true" width ="*>160" > </igc-text-column >
<igc-numeric-column field ="ProductPrice" header-text ="Price" width ="*>90" positive-prefix ="$" show-grouping-separator ="true" min-fraction-digits ="2" is-hidden ="true" > </igc-numeric-column >
<igc-numeric-column field ="OrderItems" header-text ="Orders" width ="*>110" > </igc-numeric-column >
<igc-numeric-column field ="OrderValue" header-text ="Order Value" width ="*>140" positive-prefix ="$" show-grouping-separator ="true" > </igc-numeric-column >
<igc-date-time-column field ="OrderDate" header-text ="Order Date" width ="*>135" horizontal-alignment ="right" date-time-format ="DateShort" > </igc-date-time-column >
<igc-numeric-column field ="Margin" header-text ="Margin" width ="*>110" positive-suffix ="%" horizontal-alignment ="center" is-hidden ="true" > </igc-numeric-column >
<igc-numeric-column field ="Profit" header-text ="Profit" width ="*>90" positive-prefix ="$" show-grouping-separator ="true" is-hidden ="true" > </igc-numeric-column >
<igc-text-column field ="Status" header-text ="Status" width ="*>110" horizontal-alignment ="center" > </igc-text-column >
</igc-data-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
.gridContainer {
height : calc (100% - 20px );
width : calc (100% );
padding : 10px ;
margin : 0px ;
}
.gridOptionsLabel {
font-size : 13px ;
font-family : "Verdana" ;
padding-left : 1rem ;
color : rgb (24 , 29 , 31 );
}
.columnChooserContainer {
margin : 20px ;
min-width : 225px ;
height : 500px ;
display : flex;
flex-direction : column;
padding-left : 15px ;
padding-right : 5px ;
border : 1px gray;
border-radius : 10px ;
box-shadow : 1px 1px 2px 2px rgba (50 , 50 , 50 , 0.25 );
background-color : rgb (248 , 248 , 248 );
}
.columnsOrderOptionsContainer {
margin-top : 20px ;
margin-bottom : 20px ;
}
css コピー
코드 조각
다음은 데이터 그리드에 대한 열 선택기 UI를 구현하는 방법을 보여줍니다.
<igc-column-chooser
id ="columnUI"
height ="100%"
width ="250px"
title ="Column Chooser"
show-all-text ="Show All"
hide-all-text ="Hide All" >
</igc-column-chooser >
<igc-data-grid
id ="grid"
height ="100%"
width ="100%"
data-source ={this.data}
auto-generate-columns ="false"
column-hiding-animation-mode ="SlideOver" >
<igx-text-column is-hidden ="true" field ="ProductPrice" header-text ="Product Price" > <igc-text-column >
</igc-data-grid >
html
import { IgcDataGrid } from 'igniteui-webcomponents-grids' ;
import { IgcColumnChooser } from 'igniteui-webcomponents-grids' ;
import { ColumnMovingAnimationMode } from 'igniteui-webcomponents-grids' ;
private grid: IgcDataGridComponent;
private columnChooser: IgcColumnChooserComponent;
connectedCallback ( ) {
this .columnChooser.targetGrid = this .grid;
this .columnChooser.showAllText = "Show All" ;
this .columnChooser.hideAllText = "Hide All" ;
this .grid.columnMovingAnimationMode = ColumnMovingAnimationMode.SlideOver;
}
ts
API 참조