Web Components 그리드 선택 개요
Web Components Grid의 Ignite UI for Web Components Select 기능을 사용하면 간단한 마우스 상호 작용을 사용하여 데이터와 쉽게 상호 작용하고 조작할 수 있습니다. 사용 가능한 선택 모드는 세 가지입니다.
행 선택
셀 선택
Column selection
rowSelection
속성을 사용하면 다음을 지정할 수 있습니다.
Web Components 그리드 선택 예시
아래 샘플은 세 가지 유형의 셀 선택 의 행동 IgcGridComponent
. 아래 버튼을 사용하여 사용 가능한 각 선택 모드를 활성화합니다.
import { IgcPropertyEditorPanelModule } from 'igniteui-webcomponents-layouts' ;
import 'igniteui-webcomponents-grids/grids/combined' ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebGridDescriptionModule } from 'igniteui-webcomponents-core' ;
import { IgcPropertyEditorPanelComponent, IgcPropertyEditorPropertyDescriptionComponent } from 'igniteui-webcomponents-layouts' ;
import { IgcGridComponent } from 'igniteui-webcomponents-grids/grids' ;
import NwindData from './NwindData.json' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
import { ModuleManager } from 'igniteui-webcomponents-core' ;
defineAllComponents();
import "./index.css" ;
ModuleManager.register(
IgcPropertyEditorPanelModule
);
export class Sample {
private propertyEditor: IgcPropertyEditorPanelComponent
private cellSelectionEditor: IgcPropertyEditorPropertyDescriptionComponent
private grid: IgcGridComponent
private _bind: () => void ;
constructor ( ) {
var propertyEditor = this .propertyEditor = document .getElementById('PropertyEditor' ) as IgcPropertyEditorPanelComponent;
var cellSelectionEditor = this .cellSelectionEditor = document .getElementById('CellSelectionEditor' ) as IgcPropertyEditorPropertyDescriptionComponent;
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
this ._bind = () => {
propertyEditor.componentRenderer = this .renderer;
propertyEditor.target = this .grid;
grid.data = this .nwindData;
}
this ._bind();
}
private _nwindData: any [] = NwindData;
public get nwindData (): any [] {
return this ._nwindData;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer (): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebGridDescriptionModule.register(context);
}
return this ._componentRenderer;
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</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" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample ig-typography" >
<div class ="options vertical" >
<igc-property-editor-panel
name ="PropertyEditor"
id ="PropertyEditor"
description-type ="WebGrid"
is-horizontal ="true"
is-wrapping-enabled ="true" >
<igc-property-editor-property-description
property-path ="CellSelection"
name ="CellSelectionEditor"
id ="CellSelectionEditor"
value-type ="EnumValue"
drop-down-names ="None, Single, Multiple"
drop-down-values ="NOne, Single, Multiple" >
</igc-property-editor-property-description >
</igc-property-editor-panel >
</div >
<div class ="container fill" >
<igc-grid
auto-generate ="false"
name ="grid"
id ="grid" >
<igc-column
field ="ProductID"
header ="Product ID" >
</igc-column >
<igc-column
field ="ProductName"
header ="Product Name" >
</igc-column >
<igc-column
field ="UnitsInStock"
header ="Units In Stock"
data-type ="number" >
</igc-column >
<igc-column
field ="UnitPrice"
header ="Units Price"
data-type ="number" >
</igc-column >
<igc-column
field ="Discontinued"
data-type ="boolean" >
</igc-column >
<igc-column
field ="OrderDate"
header ="Order Date"
data-type ="date" >
</igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
이 샘플이 마음에 드시나요? 당사의 완전한 Ignite UI for Web Components 툴킷에 액세스하여 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.
Web Components 그리드 선택 옵션
Ignite UI for Web Components IgcGridComponent
구성 요소는 행 선택 , 셀 선택 및 열 선택의 세 가지 선택 모드를 제공합니다. 기본적으로 Multi-cell selection mode만 활성화되어 있습니다 IgcGridComponent
. 선택 모드를 변경/활성화하려면 또는 selectable
속성을 사용할 rowSelection
cellSelection
수 있습니다.
Web Components 그리드 행 선택
rowSelection
속성을 사용하면 다음 옵션을 지정할 수 있습니다.
None
-IgcGridComponent
에 대한 행 선택이 비활성화됩니다.
Single
-IgcGridComponent
내에서 행 하나만 선택할 수 있습니다.
Multiple
- 다중 행 선택은 행 선택기를 사용하거나 ctrl + 클릭 과 같은 키 조합을 사용하거나 셀에 초점을 맞춘 후 스페이스 키를 눌러 사용할 수 있습니다.
자세한 내용은 행 선택 항목을 참조하세요.
Web Components 그리드 셀 선택
속성 cellSelection
사용하면 다음 옵션을 지정할 수 있습니다.
자세한 내용은 셀 선택 항목을 참조하세요.
Web Components 그리드 열 선택
이 selectable
속성을 사용하면 각각 IgcColumnComponent
에 대해 다음 옵션을 지정할 수 있습니다. 해당 열 선택은 이 속성이 각각 true 또는 false로 설정된 경우 활성화되거나 비활성화됩니다.
이로 인해 다음 세 가지 변형이 발생합니다.
단일 선택 - 열 셀을 마우스로 클릭합니다 .
다중 열 선택 -Ctrl + 마우스를 누른 채 열 셀을 클릭합니다 .
범위 열 선택 -Shift 키를 누른 채 마우스를 클릭하면 그 사이의 모든 항목이 선택됩니다.
자세한 내용은 열 선택 항목 으로 이동하세요.
ContextMenu
이벤트를 사용하면 사용자 정의 컨텍스트 메뉴를 추가하여 IgcGridComponent
작업을 용이하게 할 수 있습니다. 그리드 본체를 마우스 오른쪽 버튼으로 클릭 하면 이벤트가 트리거되는 셀을 방출합니다. 상황에 맞는 메뉴는 방출된 셀과 함께 작동합니다.
다중 셀 선택이 있는 경우 선택된 셀이 다중 셀 선택 영역에 있는지 확인하는 로직을 넣습니다. 그렇다면 선택한 셀의 값도 내보냅니다.
기본적으로 주요 기능은 다음과 같습니다.
public rightClick (event: any ) {
const eventArgs = event.detail;
eventArgs.event.preventDefault();
this .multiCellArgs = {};
if (this .multiCellSelection) {
const node = eventArgs.cell.selectionNode;
const isCellWithinRange = this .grid.getSelectedRanges().some((range ) => {
if (
node.column >= range.columnStart &&
node.column <= range.columnEnd &&
node.row >= range.rowStart &&
node.row <= range.rowEnd
) {
return true ;
}
return false ;
});
if (isCellWithinRange) {
this .multiCellArgs = { data : this .multiCellSelection.data };
}
}
this .contextmenuX = eventArgs.event.clientX;
this .contextmenuY = eventArgs.event.clientY;
this .clickedCell = eventArgs.cell;
this .toggleContextMenu();
}
ts
상황에 맞는 메뉴에는 다음과 같은 기능이 있습니다.
선택한 셀의 값을 복사합니다.
선택한 셀의 dataRow를 복사합니다.
선택한 셀이 다중 셀 선택 범위 내에 있는 경우 선택한 데이터를 모두 복사합니다.
public copySelectedRowData ( ) {
const selectedData = this .grid.getRowData(this .clickedCell.id.rowID);
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
public copySelectedCellData ( ) {
const selectedData = this .clickedCell.value;
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
public copySelectedData ( ) {
const selectedData = this .grid.getSelectedData();
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
private copyData (data: any [] ) {
const tempElement = document .createElement('input' );
document .body.appendChild(tempElement);
tempElement.setAttribute('id' , 'temp_id' );
(document .getElementById('temp_id' ) as HTMLInputElement).value = JSON .stringify(data);
tempElement.select();
document .execCommand('copy' );
document .body.removeChild(tempElement);
}
ts
IgcGridComponent
는 복사된 데이터를 가져와서 컨테이너 요소에 붙여넣습니다.
그리드와 컨텍스트 메뉴를 결합하는 데 사용할 템플릿은 다음과 같습니다.
<div class ="container sample" >
<div class ="wrapper" >
<igc-grid auto-generate ="false" width ="50%" height ="100%" name ="grid" id ="grid" >
<igc-column field ="ProductID" header ="Product ID" >
</igc-column >
<igc-column field ="ProductName" header ="Product Name" >
</igc-column >
<igc-column field ="UnitsInStock" header ="Units In Stock" data-type ="number" >
</igc-column >
<igc-column field ="UnitPrice" header ="Units Price" data-type ="number" >
</igc-column >
<igc-column field ="Discontinued" data-type ="boolean" >
</igc-column >
<igc-column field ="OrderDate" header ="Order Date" data-type ="date" >
</igc-column >
</igc-grid >
<div id ="selectedArea" class ="selected-data-area" >
</div >
</div >
</div >
<div id ="menu" style ="display: none;" class ="contextmenu" >
<span id ="copySingleCell" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Cell Data
</span >
<span id ="copyRow" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Row Data
</span >
<span id ="copyMultiCells" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Cells Data
</span >
</div >
</div >
html
여러 셀을 선택하고 마우스 오른쪽 버튼을 누릅니다. 상황에 맞는 메뉴가 나타나고 셀 데이터 복사를 선택하면 선택한 데이터가 오른쪽 빈 상자에 나타납니다.
결과는 다음과 같습니다.
export class NwindDataItem {
public constructor (init: Partial<NwindDataItem> ) {
Object .assign(this , init);
}
public ProductID: number ;
public ProductName: string ;
public SupplierID: number ;
public CategoryID: number ;
public QuantityPerUnit: string ;
public UnitPrice: number ;
public UnitsInStock: number ;
public UnitsOnOrder: number ;
public ReorderLevel: number ;
public Discontinued: boolean ;
public OrderDate: string ;
public Rating: number ;
public Locations: NwindDataItem_LocationsItem[];
}
export class NwindDataItem_LocationsItem {
public constructor (init: Partial<NwindDataItem_LocationsItem> ) {
Object .assign(this , init);
}
public Shop: string ;
public LastInventory: string ;
}
export class NwindData extends Array <NwindDataItem > {
public constructor ( ) {
super ();
this .push(new NwindDataItem(
{
ProductID : 1 ,
ProductName : `Chai` ,
SupplierID : 1 ,
CategoryID : 1 ,
QuantityPerUnit : `10 boxes x 20 bags` ,
UnitPrice : 18 ,
UnitsInStock : 39 ,
UnitsOnOrder : 30 ,
ReorderLevel : 10 ,
Discontinued : false ,
OrderDate : `2012-02-12` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Fun-Tasty Co.` ,
LastInventory : `06/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 2 ,
ProductName : `Chang` ,
SupplierID : 1 ,
CategoryID : 1 ,
QuantityPerUnit : `24 - 12 oz bottles` ,
UnitPrice : 19 ,
UnitsInStock : 17 ,
UnitsOnOrder : 40 ,
ReorderLevel : 25 ,
Discontinued : true ,
OrderDate : `2003-03-17` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 3 ,
ProductName : `Aniseed Syrup` ,
SupplierID : 1 ,
CategoryID : 2 ,
QuantityPerUnit : `12 - 550 ml bottles` ,
UnitPrice : 10 ,
UnitsInStock : 13 ,
UnitsOnOrder : 70 ,
ReorderLevel : 25 ,
Discontinued : false ,
OrderDate : `2006-03-17` ,
Rating : 3 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Street Market` ,
LastInventory : `12/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `24/7 Market` ,
LastInventory : `11/11/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 4 ,
ProductName : `Chef Antons Cajun Seasoning` ,
SupplierID : 2 ,
CategoryID : 2 ,
QuantityPerUnit : `48 - 6 oz jars` ,
UnitPrice : 22 ,
UnitsInStock : 53 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2016-03-17` ,
Rating : 3 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Fun-Tasty Co.` ,
LastInventory : `06/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Street Market` ,
LastInventory : `12/12/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 5 ,
ProductName : `Chef Antons Gumbo Mix` ,
SupplierID : 2 ,
CategoryID : 2 ,
QuantityPerUnit : `36 boxes` ,
UnitPrice : 21.35 ,
UnitsInStock : 0 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : true ,
OrderDate : `2011-11-11` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 6 ,
ProductName : `Grandmas Boysenberry Spread` ,
SupplierID : 3 ,
CategoryID : 2 ,
QuantityPerUnit : `12 - 8 oz jars` ,
UnitPrice : 25 ,
UnitsInStock : 0 ,
UnitsOnOrder : 30 ,
ReorderLevel : 25 ,
Discontinued : false ,
OrderDate : `2017-12-17` ,
Rating : 4 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 7 ,
ProductName : `Uncle Bobs Organic Dried Pears` ,
SupplierID : 3 ,
CategoryID : 7 ,
QuantityPerUnit : `12 - 1 lb pkgs.` ,
UnitPrice : 30 ,
UnitsInStock : 150 ,
UnitsOnOrder : 30 ,
ReorderLevel : 10 ,
Discontinued : false ,
OrderDate : `2016-07-17` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Fun-Tasty Co.` ,
LastInventory : `06/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Street Market` ,
LastInventory : `12/12/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 8 ,
ProductName : `Northwoods Cranberry Sauce` ,
SupplierID : 3 ,
CategoryID : 2 ,
QuantityPerUnit : `12 - 12 oz jars` ,
UnitPrice : 40 ,
UnitsInStock : 6 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2018-01-17` ,
Rating : 4 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Fun-Tasty Co.` ,
LastInventory : `06/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 9 ,
ProductName : `Mishi Kobe Niku` ,
SupplierID : 4 ,
CategoryID : 6 ,
QuantityPerUnit : `18 - 500 g pkgs.` ,
UnitPrice : 97 ,
UnitsInStock : 29 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : true ,
OrderDate : `2010-02-17` ,
Rating : 4 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 10 ,
ProductName : `Ikura` ,
SupplierID : 4 ,
CategoryID : 8 ,
QuantityPerUnit : `12 - 200 ml jars` ,
UnitPrice : 31 ,
UnitsInStock : 31 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2008-05-17` ,
Rating : 3 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Wall Market` ,
LastInventory : `12/06/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 11 ,
ProductName : `Queso Cabrales` ,
SupplierID : 5 ,
CategoryID : 4 ,
QuantityPerUnit : `1 kg pkg.` ,
UnitPrice : 21 ,
UnitsInStock : 22 ,
UnitsOnOrder : 30 ,
ReorderLevel : 30 ,
Discontinued : false ,
OrderDate : `2009-01-17` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Fun-Tasty Co.` ,
LastInventory : `06/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 12 ,
ProductName : `Queso Manchego La Pastora` ,
SupplierID : 5 ,
CategoryID : 4 ,
QuantityPerUnit : `10 - 500 g pkgs.` ,
UnitPrice : 38 ,
UnitsInStock : 86 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2015-11-17` ,
Rating : 3 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 13 ,
ProductName : `Konbu` ,
SupplierID : 6 ,
CategoryID : 8 ,
QuantityPerUnit : `2 kg box` ,
UnitPrice : 6 ,
UnitsInStock : 24 ,
UnitsOnOrder : 30 ,
ReorderLevel : 5 ,
Discontinued : false ,
OrderDate : `2015-03-17` ,
Rating : 2 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 14 ,
ProductName : `Tofu` ,
SupplierID : 6 ,
CategoryID : 7 ,
QuantityPerUnit : `40 - 100 g pkgs.` ,
UnitPrice : 23.25 ,
UnitsInStock : 35 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2017-06-17` ,
Rating : 4 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Street Market` ,
LastInventory : `12/12/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 15 ,
ProductName : `Genen Shouyu` ,
SupplierID : 6 ,
CategoryID : 2 ,
QuantityPerUnit : `24 - 250 ml bottles` ,
UnitPrice : 15.5 ,
UnitsInStock : 39 ,
UnitsOnOrder : 30 ,
ReorderLevel : 5 ,
Discontinued : false ,
OrderDate : `2014-03-17` ,
Rating : 4 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Local Market` ,
LastInventory : `07/03/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Wall Market` ,
LastInventory : `12/06/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 16 ,
ProductName : `Pavlova` ,
SupplierID : 7 ,
CategoryID : 3 ,
QuantityPerUnit : `32 - 500 g boxes` ,
UnitPrice : 17.45 ,
UnitsInStock : 29 ,
UnitsOnOrder : 30 ,
ReorderLevel : 10 ,
Discontinued : false ,
OrderDate : `2018-03-28` ,
Rating : 2 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Street Market` ,
LastInventory : `12/12/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `24/7 Market` ,
LastInventory : `11/11/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 17 ,
ProductName : `Alice Mutton` ,
SupplierID : 7 ,
CategoryID : 6 ,
QuantityPerUnit : `20 - 1 kg tins` ,
UnitPrice : 39 ,
UnitsInStock : 0 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : true ,
OrderDate : `2015-08-17` ,
Rating : 2 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Farmer Market` ,
LastInventory : `04/04/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 18 ,
ProductName : `Carnarvon Tigers` ,
SupplierID : 7 ,
CategoryID : 8 ,
QuantityPerUnit : `16 kg pkg.` ,
UnitPrice : 62.5 ,
UnitsInStock : 42 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2005-09-27` ,
Rating : 2 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `24/7 Market` ,
LastInventory : `11/11/2018`
}),
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 19 ,
ProductName : `Teatime Chocolate Biscuits` ,
SupplierID : 8 ,
CategoryID : 3 ,
QuantityPerUnit : `` ,
UnitPrice : 9.2 ,
UnitsInStock : 25 ,
UnitsOnOrder : 30 ,
ReorderLevel : 5 ,
Discontinued : false ,
OrderDate : `2001-03-17` ,
Rating : 2 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Local Market` ,
LastInventory : `07/03/2018`
})]
}));
this .push(new NwindDataItem(
{
ProductID : 20 ,
ProductName : `Sir Rodneys Marmalade` ,
SupplierID : 8 ,
CategoryID : 3 ,
QuantityPerUnit : `4 - 100 ml jars` ,
UnitPrice : 4.5 ,
UnitsInStock : 40 ,
UnitsOnOrder : 30 ,
ReorderLevel : 0 ,
Discontinued : false ,
OrderDate : `2005-03-17` ,
Rating : 5 ,
Locations : [
new NwindDataItem_LocationsItem(
{
Shop : `Super Market` ,
LastInventory : `09/09/2018`
})]
}));
}
}
ts コピー import { IgcPropertyEditorPanelModule } from 'igniteui-webcomponents-layouts' ;
import 'igniteui-webcomponents-grids/grids/combined' ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebGridDescriptionModule } from 'igniteui-webcomponents-core' ;
import { IgcPropertyEditorPanelComponent, IgcPropertyEditorPropertyDescriptionComponent } from 'igniteui-webcomponents-layouts' ;
import { IgcGridComponent } from 'igniteui-webcomponents-grids/grids' ;
import { NwindDataItem, NwindDataItem_LocationsItem, NwindData } from './NwindData' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import { defineAllComponents, registerIconFromText } from 'igniteui-webcomponents' ;
import "./index.css" ;
defineAllComponents();
export class Sample {
private grid: IgcGridComponent;
public contextmenu = false ;
public contextmenuX = 0 ;
public contextmenuY = 0 ;
public clickedCell: any = null ;
public copiedData: any ;
public multiCellSelection: { data : any [] } = { data : [] };
public multiCellArgs: any ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
grid.data = this .nwindData;
this .rightClick = this .rightClick.bind(this );
this .copySelectedData = this .copySelectedData.bind(this );
this .copySelectedRowData = this .copySelectedRowData.bind(this );
this .copySelectedCellData = this .copySelectedCellData.bind(this );
document .getElementById('copySingleCell' ).addEventListener("click" , this .copySelectedCellData);
document .getElementById('copyRow' ).addEventListener("click" , this .copySelectedRowData);
document .getElementById('copyMultiCells' ).addEventListener("click" , this .copySelectedData);
grid.addEventListener("contextMenu" , this .rightClick);
const icon = `<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 -960 960 960" width="48"><path d="M180-81q-24 0-42-18t-18-42v-603h60v603h474v60H180Zm120-120q-24 0-42-18t-18-42v-560q0-24 18-42t42-18h440q24 0 42 18t18 42v560q0 24-18 42t-42 18H300Zm0-60h440v-560H300v560Zm0 0v-560 560Z"/></svg>` ;
registerIconFromText("content_copy" , icon);
}
private _nwindData: NwindData = null ;
public get nwindData (): NwindData {
if (this ._nwindData == null ) {
this ._nwindData = new NwindData();
}
return this ._nwindData;
}
public rightClick (event: any ) {
const eventArgs = event.detail;
eventArgs.event.preventDefault();
this .multiCellArgs = {};
if (this .multiCellSelection) {
const node = eventArgs.cell;
const isCellWithinRange = this .grid.getSelectedRanges().some((range ) => {
if (
node.columnIndex >= range.columnStart &&
node.columnIndex <= range.columnEnd &&
node.rowIndex >= range.rowStart &&
node.rowIndex <= range.rowEnd
) {
return true ;
}
return false ;
});
if (isCellWithinRange) {
this .multiCellArgs = { data : this .multiCellSelection.data };
}
}
this .contextmenuX = eventArgs.event.clientX;
this .contextmenuY = eventArgs.event.clientY;
this .clickedCell = eventArgs.cell;
this .toggleContextMenu();
}
public toggleContextMenu ( ) {
this .contextmenu = !this .contextmenu;
const menu = document .getElementById('menu' );
if (this .contextmenu) {
menu.style.left = this .contextmenuX + "px" ;
menu.style.top = this .contextmenuY + "px" ;
menu.style.display = "" ;
} else {
menu.style.display = "none" ;
}
}
public copySelectedRowData ( ) {
const selectedData = this .grid.getRowData(this .clickedCell.cellID.rowID);
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
public copySelectedCellData ( ) {
const selectedData = this .clickedCell.value;
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
public copySelectedData ( ) {
const selectedData = this .grid.getSelectedData();
this .copyData(selectedData);
const selectedDataArea = document .getElementById('selectedArea' );
selectedDataArea.innerText = JSON .stringify(selectedData);
this .toggleContextMenu();
}
private copyData (data: any [] ) {
const tempElement = document .createElement('input' );
document .body.appendChild(tempElement);
tempElement.setAttribute('id' , 'temp_id' );
(document .getElementById('temp_id' ) as HTMLInputElement).value = JSON .stringify(data);
tempElement.select();
document .execCommand('copy' );
document .body.removeChild(tempElement);
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</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" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample" >
<div class ="wrapper" >
<igc-grid auto-generate ="false" width ="50%" height ="100%" name ="grid" id ="grid" >
<igc-column field ="ProductID" header ="Product ID" >
</igc-column >
<igc-column field ="ProductName" header ="Product Name" >
</igc-column >
<igc-column field ="UnitsInStock" header ="Units In Stock" data-type ="number" >
</igc-column >
<igc-column field ="UnitPrice" header ="Units Price" data-type ="number" >
</igc-column >
<igc-column field ="Discontinued" data-type ="boolean" >
</igc-column >
<igc-column field ="OrderDate" header ="Order Date" data-type ="date" >
</igc-column >
</igc-grid >
<div id ="selectedArea" class ="selected-data-area" >
</div >
</div >
</div >
<div id ="menu" style ="display: none;" class ="contextmenu" >
<span id ="copySingleCell" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Cell Data
</span >
<span id ="copyRow" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Row Data
</span >
<span id ="copyMultiCells" class ="item" >
<igc-icon name ="content_copy" > </igc-icon >Copy Cells Data
</span >
</div >
</div >
<% if (false) { %>
<script src ="src/index.ts" > </script >
<% } %>
</body >
</html >
html コピー
.contextmenu {
position : absolute;
width : 180px ;
background : white;
display : flex;
cursor : context-menu;
flex-direction : column;
box-shadow : 0 1px 3px 0 rgba (0 , 0 , 0 , 0.2 ), 0 1px 1px 0 rgba (0 , 0 , 0 , 0.14 ), 0 2px 1px -1px rgba (0 , 0 , 0 , 0.12 );
z-index : 9999 ;
font-size : 0.75rem ;
font-weight : 650 ;
}
.item {
padding : 10px ;
display : flex;
}
.item :hover {
background :rgb (204 , 203 , 203 );
}
.icon {
vertical-align : middle;
margin-bottom : 5px ;
margin-right : 5px ;
}
.selected-data-area {
overflow-y : auto;
width : 50% ;
box-shadow : 0 1px 3px 0 rgba (0 , 0 , 0 , 0.2 ), 0 1px 1px 0 rgba (0 , 0 , 0 , 0.14 ), 0 2px 1px -1px rgba (0 , 0 , 0 , 0.12 );
margin-left : 10px ;
}
.wrapper {
margin : 10px ;
display : flex;
justify-content : space-evenly;
}
css コピー
알려진 문제 및 제한 사항
그리드에 primaryKey
설정되지 않고 원격 데이터 시나리오가 활성화된 경우(그리드에 표시할 데이터를 검색하기 위해 원격 서버에 대한 페이징, 정렬, 필터링, 스크롤 트리거 요청 시) 행은 데이터 이후 다음 상태를 잃습니다. 요청이 완료되었습니다:
API 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.