Web Components 그리드 검색 필터
Web Components 그리드의 Ignite UI for Web Components 검색 필터 기능을 사용하면 데이터 컬렉션에서 값을 찾는 프로세스를 수행할 수 있습니다. 이 기능을 더 쉽게 설정할 수 있으며 검색 입력 상자, 버튼, 키보드 탐색 및 기타 유용한 기능을 사용하여 더 나은 사용자 경험을 제공할 수 있습니다. 브라우저는 기본적으로 콘텐츠 검색 기능을 제공하지만 대부분의 경우 IgcGridComponent
보이지 않는 열과 행을 가상화합니다. 이러한 경우 기본 브라우저 검색은 DOM의 일부가 아니기 때문에 가상화된 셀의 데이터를 검색할 수 없습니다. Web Components Material 테이블 기반 그리드를 확장했습니다. 검색 API 이를 통해 검색할 수 있습니다. 가상화된 콘텐츠 의 IgcGridComponent
.
Web Components 검색 예제
다음 예는 모든 열과 행을 검색할 수 있는 검색 입력 상자와 각 열에 대한 특정 필터링 옵션이 있는 IgcGridComponent
나타냅니다.
export class MarketRecord {
public constructor (init: Partial<MarketRecord> ) {
Object .assign(this , init);
}
public IndustryGroup: string ;
public IndustrySector: string ;
public SectorType: string ;
public KRD: number ;
public MarketNotion: number ;
public Date : string ;
}
export class MarketData extends Array <MarketRecord >
{
public constructor ( ) {
super ();
this .push(new MarketRecord(
{
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
};
}
ts コピー import 'igniteui-webcomponents-grids/grids/combined' ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import { IgcGridComponent } from 'igniteui-webcomponents-grids/grids' ;
import { defineComponents, IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent, registerIconFromText } from 'igniteui-webcomponents' ;
import { MarketData } from './MarketData' ;
import "./index.css" ;
defineComponents(IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent);
export class Sample {
private grid: IgcGridComponent;
private searchBox: IgcInputComponent;
private searchIcon: IgcIconComponent;
private clearIcon: IgcIconComponent;
private nextIconButton: IgcIconButtonComponent;
private prevIconButton: IgcIconButtonComponent;
private caseSensitiveChip: IgcChipComponent;
private exactMatchChip: IgcChipComponent;
private data: MarketData;
private _bind: () => void ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
this .nextSearch = this .nextSearch.bind(this );
this .prevSearch = this .prevSearch.bind(this );
this .clearSearch = this .clearSearch.bind(this );
const prevIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z'></path></svg>" ;
const nextIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'></path></svg>" ;
const clearIconText = "<svg width='24' height='24' viewBox='0 0 24 24' title='Clear'><path d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'></path></svg>" ;
const searchIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z' /></svg>" ;
registerIconFromText("prev" , prevIconText, "material" );
registerIconFromText("next" , nextIconText, "material" );
registerIconFromText("clear" , clearIconText, "material" );
registerIconFromText("search" , searchIconText, "material" );
var searchIcon = this .searchIcon = document .getElementById('searchIcon' ) as IgcIconComponent;
var nextIconButton = this .nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
var prevIconButton = this .prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
this .caseSensitiveChip = document .getElementById('caseSensitiveChip' ) as IgcChipComponent;
this .exactMatchChip = document .getElementById('exactMatchChip' ) as IgcChipComponent;
var searchBox = this .searchBox = document .getElementById('searchBox' ) as IgcInputComponent;
this .data = new MarketData();
this ._bind = () => {
grid.data = this .data;
searchBox.addEventListener("keydown" , (evt ) => { this .onSearchKeydown(evt); });
this .searchBox.addEventListener("igcInput" , (evt ) => {
this .searchIcon.name = evt.detail ? 'clear' : 'search' ;
this .grid.findNext(evt.detail, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
});
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
searchIcon.addEventListener("click" , this .clearSearch);
}
this ._bind();
}
public onSearchKeydown (evt: KeyboardEvent ) {
if (evt.key === 'Enter' || evt.key === 'ArrowDown' ) {
evt.preventDefault();
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
} else if (evt.key === 'ArrowUp' ) {
evt.preventDefault();
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public clearSearch ( ) {
this .searchBox.value = "" ;
this .grid.clearSearch();
this .searchIcon.name = 'search' ;
}
}
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 ="container vertical" >
<div style ="margin-bottom: 1rem" >
<igc-input id ="searchBox" name ="searchBox" >
<igc-icon id ="searchIcon" slot ="prefix" name ="search" collection ="material" > </igc-icon >
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
</igc-input >
</div >
<igc-grid class ="gridSize" auto-generate ="false" id ="grid" name ="grid" allow-filtering ="true" height ="100%" width ="100%" >
<igc-column field ="IndustrySector" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="IndustryGroup" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="SectorType" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="KRD" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="MarketNotion" data-type ="number" sortable ="true" > </igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
.gridSize {
--ig-size: var (--ig-size-small);
}
css コピー
이 샘플이 마음에 드시나요? 당사의 완전한 Ignite UI for Web Components 툴킷에 액세스하여 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.
Web Components 검색 사용
그리드 설정
그리드를 생성하고 이를 데이터에 바인딩하는 것부터 시작해 보겠습니다. 또한 우리가 사용할 구성 요소에 대한 몇 가지 사용자 정의 스타일을 추가할 것입니다!
.gridSize {
--ig-size: var (--ig-size-small);
}
css
<igc-grid id ="grid1" class ="gridSize" auto-generate ="false" allow-filtering ="true" >
<igc-column field ="IndustrySector" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="IndustryGroup" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="SectorType" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="KRD" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="MarketNotion" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="Date" data-type ="date" sortable ="true" > </igc-column >
</igc-grid >
html
좋습니다. 이제 IgcGridComponent
의 검색 API를 준비하겠습니다! 현재 검색된 텍스트를 저장하고 검색이 대소문자를 구분하는지 및/또는 정확히 일치하는지 여부를 저장하는 데 사용할 수 있는 몇 가지 속성을 만들 수 있습니다.
private grid: IgcGridComponent;
private searchBox: IgcInputComponent;
private searchIcon: IgcIconComponent;
private clearIcon: IgcIconComponent;
private nextIconButton: IgcIconButtonComponent;
private prevIconButton: IgcIconButtonComponent;
private caseSensitiveChip: IgcChipComponent;
private exactMatchChip: IgcChipComponent;
typescript
이제 검색 입력을 만들어 보겠습니다! 입력 요소를 가져옴으로써 현재 값을 얻을 수 있습니다. 이를 통해 IgcGridComponent
의 findNext
및 findPrev
메소드를 사용하여 SearchText
의 모든 항목을 강조 표시하고 다음/이전 항목으로 스크롤할 수 있습니다(호출한 메소드에 따라 다름).
findNext
및 findPrev
메소드에는 모두 세 가지 인수가 있습니다.
Text
: string (검색하려는 텍스트)
(선택 사항) CaseSensitive
: 부울 (검색 시 대소문자를 구분해야 하는지 여부, 기본값은 false입니다.)
(선택 사항) ExactMatch
: 부울 (정확한 일치로 검색해야 하는지 여부, 기본값은 false입니다.)
정확한 일치로 검색할 때 검색 API는 대소문자 구분도 고려하여 SearchText
와 완전히 일치하는 셀 값만 결과로 강조 표시합니다. 예를 들어 'software ' 및 'Software ' 문자열은 대소문자 구분을 무시하고 정확히 일치합니다.
위의 메소드는 숫자 값(IgcGridComponent
에 지정된 문자열이 포함된 횟수)을 반환합니다.
<igc-input id ="searchBox" name ="searchBox" >
</igc-input >
html
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
this .searchBox = document .getElementById('searchBox' ) as IgcInputComponent;
grid.data = new MarketData();
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, false , false );
}
ts
검색 결과를 자유롭게 검색하고 탐색하기 위해 버튼의 각 클릭 이벤트 핸들러 내에서 findNext
및 findPrev
메소드를 호출하여 두 개의 버튼을 만들어 보겠습니다.
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
html
constructor ( ) {
var nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
var prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
ts
키보드 검색 추가
또한 사용자가 키보드의 화살표 키와 입력하다 열쇠. 이를 달성하기 위해 우리는 다음을 처리할 수 있습니다. 키다운 입력의 기본 캐럿 이동을 방지하여 검색 입력 이벤트 PreventDefault
메서드를 호출하고 findNext
/ findPrev
사용자가 어떤 키를 눌렀는지에 따라 방법이 달라집니다.
<input id ="searchBox" name ="searchBox" />
html
constructor ( ) {
searchBox.addEventListener("keydown" , (evt ) => { this .onSearchKeydown(evt); });
this .searchBox.addEventListener("igcInput" , (evt ) => {
this .searchIcon.name = evt.detail ? 'clear' : 'search' ;
this .grid.findNext(evt.detail, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
});
}
public onSearchKeydown (evt: KeyboardEvent ) {
if (evt.key === 'Enter' || evt.key === 'ArrowDown' ) {
evt.preventDefault();
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
} else if (evt.key === 'ArrowUp' ) {
evt.preventDefault();
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
}
}
typescript
대소문자 구분 및 정확한 일치
이제 사용자가 검색에서 대소문자를 구분할지 또는 정확히 일치할지 여부를 선택할 수 있도록 하겠습니다. 이를 위해 간단한 체크박스 입력을 사용하고 체크박스 checked
상태를 사용할 수 있는 change
이벤트에 바인딩할 수 있습니다.
<span > Case sensitive</span >
<input id ="case" type ="checkbox" >
<span > Exact match</span >
<input id ="exact" type ="checkbox" >
html
constructor ( ) {
const case = document .getElementById("case" ) as HTMLInputElement;
const exact = document .getElementById("exact" ) as HTMLInputElement;
case .addEventListener("change" , this .updateSearch);
exact.addEventListener("change" , this .updateSearch);
}
public updateSearch ( ) {
const search1 = document .getElementById("search1" ) as HTMLInputElement;
const case = document .getElementById("case" ) as HTMLInputElement;
const exact = document .getElementById("exact" ) as HTMLInputElement;
const grid = document .getElementById("grid" ) as IgcGridComponent;
grid.findNext(search1.value, case .checked, exact.checked);
}
typescript
고집
IgcGridComponent
를 필터링 및 정렬하거나 레코드를 추가 및 제거하려면 어떻게 해야 합니까? 이러한 작업 후에는 현재 검색의 하이라이트가 자동으로 업데이트되어 SearchText
와 일치하는 모든 텍스트에 대해 지속됩니다! 또한 검색은 페이징과 함께 작동하며 IgcGridComponent
의 PerPage
속성 변경을 통해 강조 표시를 유지합니다.
아이콘 추가
다른 구성 요소 중 일부를 사용하면 풍부한 사용자 인터페이스를 만들고 전체 검색 창의 전반적인 디자인을 개선할 수 있습니다! 검색 입력 왼쪽에는 멋진 검색 또는 삭제 아이콘이 있고, 검색 옵션을 위한 몇 가지 칩이 있으며, 오른쪽에는 탐색을 위한 멋진 잔물결 스타일 버튼과 결합된 일부 머티리얼 디자인 아이콘이 있습니다. 보다 세련된 디자인을 위해 이러한 구성 요소를 입력 그룹 내에 래핑할 수 있습니다.
import { defineComponents, IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent, registerIconFromText } from "igniteui-webcomponents" ;
defineComponents(IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent);
typescript
마지막으로 템플릿을 새로운 구성요소로 업데이트해 보겠습니다.
<igc-input id ="searchBox" name ="searchBox" >
<igc-icon id ="searchIcon" slot ="prefix" name ="search" collection ="material" > </igc-icon >
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
</igc-input >
html
constructor ( ) {
const prevIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z'></path></svg>" ;
const nextIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'></path></svg>" ;
const clearIconText = "<svg width='24' height='24' viewBox='0 0 24 24' title='Clear'><path d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'></path></svg>" ;
const searchIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z' /></svg>" ;
registerIconFromText("prev" , prevIconText, "material" );
registerIconFromText("next" , nextIconText, "material" );
registerIconFromText("clear" , clearIconText, "material" );
registerIconFromText("search" , searchIconText, "material" );
}
typescript
입력 그룹 오른쪽에 다음 목적을 가진 세 개의 별도 컨테이너를 만들어 보겠습니다.
CaseSensitive
및 ExactMatch
속성을 전환하는 몇 가지 칩을 표시합니다. 우리는 체크박스를 이러한 속성에 따라 색상을 변경하는 두 개의 세련된 칩으로 대체했습니다. 칩을 클릭할 때마다 해당 핸들러를 호출합니다.
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
html
constructor ( ) {
const input = document .getElementById("searchBox" ) as IgcInputComponent;
input.addEventListener("change" , this .updateSearch);
}
public updateSearch ( ) {
const grid = document .getElementById('grid' ) as IgcGridComponent;
const caseSensitiveChip = document .getElementById('caseSensitiveChip' ) as IgcChipComponent;
const exactMatchChip = document .getElementById('exactMatchChip' ) as IgcChipComponent;
grid.findNext(input.value, caseSensitiveChip.selected, exactMatchChip.selected);
}
ts
검색 탐색 버튼의 경우 입력을 머티리얼 아이콘이 있는 잔물결 스타일 버튼으로 변환했습니다. 클릭 이벤트에 대한 핸들러는 동일하게 유지되며 findNext
/ findPrev
메소드를 호출합니다.
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
html
constructor ( ) {
const nextIconButton = this .nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
const prevIconButton = this .prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
}
typescript
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
ts
알려진 제한 사항
한정
설명
템플릿을 사용하여 셀에서 검색
검색 기능 강조 표시는 기본 셀 템플릿에서만 작동합니다. 사용자 정의 셀 템플릿이 포함된 열이 있는 경우 강조 표시가 작동하지 않으므로 열 포맷터와 같은 대체 접근 방식을 사용하거나searchable
열의 속성을 false로 설정합니다.
원격 가상화
원격 가상화를 사용하면 검색이 제대로 작동하지 않습니다.
텍스트가 잘린 셀
셀의 텍스트가 너무 커서 맞지 않고 찾고 있는 텍스트가 줄임표로 잘려도 셀로 스크롤하여 일치 횟수에 포함시키지만 아무것도 강조 표시되지 않습니다.
API 참조
이 기사에서는 검색 결과 사이를 탐색할 때 몇 가지 추가 기능과 함께 자체 검색 표시줄 IgcGridComponent
을 구현했습니다. 또한 아이콘, 칩 및 입력과 같은 몇 가지 추가 Ignite UI for Web Components 구성 요소를 사용했습니다. 검색 API는 다음과 같습니다.
IgcGridComponent
methods:
IgcColumnComponent
properties:
사용된 관련 API가 포함된 추가 구성요소:
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.