Blazor 계층적 그리드 셀 편집

    Blazor 계층형 그리드의 Ignite UI for Blazor Blazor 계층형 그리드 구성 요소 내의 개별 셀의 내용에 대한 뛰어난 데이터 조작 기능을 제공하며 React CRUD 작업을 위한 강력한 API와 함께 제공됩니다. 스프레드시트, 데이터 테이블 및 데이터 그리드와 같은 앱에서 기본적인 기능으로, 사용자가 특정 셀 내에서 데이터를 추가, 편집 또는 업데이트할 수 있습니다. 기본적으로 Ignite UI for Blazor의 그리드는 셀 편집에 사용됩니다. 그리고 기본 셀 편집 템플릿으로 인해 폼 상단의 열 데이터 유형에 따라 다른 편집기가 있습니다.

    또한 데이터 업데이트 작업에 대한 사용자 정의 템플릿을 정의하고 변경 사항 커밋 및 삭제에 대한 기본 동작을 재정의할 수 있습니다.

    Blazor Hierarchical Grid Cell Editing and Edit Templates Example

    EXAMPLE
    DATA
    MODULES
    RAZOR
    CSS

    Like this sample? Get access to our complete Ignite UI for Blazor toolkit and start building your own apps in minutes. Download it for free.

    셀 편집

    Editing through UI

    다음 방법 중 하나로 편집 가능한 셀에 초점이 맞춰지면 특정 셀에 대한 편집 모드로 들어갈 수 있습니다.

    • 두 번 클릭하면;
    • 한 번 클릭 시 - 이전에 선택한 셀이 편집 모드이고 현재 선택한 셀이 편집 가능한 경우에만 한 번 클릭하면 편집 모드로 들어갑니다. 이전에 선택한 셀이 편집 모드가 아닌 경우 한 번 클릭하면 편집 모드로 들어가지 않고 셀이 선택됩니다.
    • 키를 누르면 Enter;
    • 키를 누르면 F2;

    다음 방법 중 하나로 변경 사항을 커밋하지 않고 편집 모드를 종료할 수 있습니다.

    • 키를 누를 때 Escape;
    • 정렬, 필터링, 검색숨기기 작업을 수행할 때

    다음 방법 중 하나로 편집 모드를 종료하고 변경 사항을 커밋 할 수 있습니다.

    • 키를 누르면 Enter;
    • 키를 누르면 F2;
    • 키를 누를 때 Tab;
    • 다른 셀을 한 번 클릭할 때 - 에서 IgbHierarchicalGrid 다른 셀을 클릭하면 변경 사항이 제출됩니다.
    • 페이징, 크기 조정, 고정 또는 이동과 같은 작업을 수행하면 편집 모드가 종료되고 변경 사항이 제출됩니다.

    The cell remains in edit mode when you scroll vertically or horizontally or click outside the IgbHierarchicalGrid. This is valid for both cell editing and row editing.

    Editing through API

    API를 IgbHierarchicalGrid 통해 셀 값을 수정할 수도 있지만 기본 키가 정의된 경우에만 가능합니다.

    @code {
        this.hierarchicalGrid.UpdateCell(newValue, rowID, 'ReorderLevel');
    }
    razor

    셀을 업데이트하는 또 다른 방법은 다음과 같은 방법을 사용하는 Update 것입니다. Cell

    @code {
        private UpdateCell() {
            IgbCell cell = this.hierarchicalGrid.GetCellByColumn(rowIndex, "ReorderLevel");
            cell.Update(70);
        }
    }
    razor

    Cell Editing Templates

    일반 편집 항목에서 기본 셀 편집 템플릿에 대해 자세히 알아보고 확인할 수 있습니다.

    셀에 적용될 사용자 정의 템플릿을 제공하려는 경우 해당 템플릿을 셀 자체나 헤더에 전달할 수 있습니다. 먼저 평소와 같이 열을 만듭니다.

    <IgbColumn
        Field="Age"
        DataType="GridColumnDataType.String"
        InlineEditorTemplateScript="WebGridCellEditCellTemplate"
        Editable="true"
        Name="column1"
        @ref="column1">
    </IgbColumn>
    razor

    템플릿을 전달합니다.

    *** In JavaScript ***
    
    igRegisterScript("WebGridCellEditCellTemplate", (ctx) => {
        let cellValues = [];
        let uniqueValues = [];
        for(const i of ctx.cell.grid.data){
            const field = ctx.cell.column.field;
            if(uniqueValues.indexOf(i[field]) === -1 )
            {
                cellValues.push(html`<igc-select-item value=${i[field]}>${(i[field])}</igc-select-item>`);
                uniqueValues.push(i[field]);
            }
        }
        return html`<div>
        <igc-select position-strategy="fixed" @igcChange=${ e => ctx.cell.editValue = e.detail.value}>
              ${cellValues}
        </igc-select>
    </div>`;
    }, false);
    razor

    추가 참조를 위해 위의 작업 샘플을 여기에서 찾을 수 있습니다.

    EXAMPLE
    DATA
    MODULES
    RAZOR
    JS
    CSS

    CRUD operations

    Please keep in mind that when you perform some CRUD operation all of the applied pipes like filtering, sorting and grouping will be re-applied and your view will be automatically updated.

    IgbHierarchicalGrid 기본 CRUD 작업을 위한 간단한 API를 제공합니다.

    Adding a new record

    IgbHierarchicalGrid 구성 요소는 제공된 데이터를 데이터 소스 자체에 추가하는 메서드를 노출 AddRow 합니다.

    @code {
        //Assuming we have a `GetNewRecord` method returning the new row data.
        const record = this.GetNewRecord();
        this.HierarchicalGridRef.AddRow(record);
    }
    razor

    Updating data in the Hierarchical Grid

    계층적 그리드의 데이터 업데이트는 및 UpdateCell 메서드를 통해 UpdateRow 수행되지만 그리드에 대한 PrimaryKey가 정의된 경우에만 수행됩니다. 각각의 업데이트 방법을 통해 셀 및/또는 행 값을 직접 업데이트할 수도 있습니다.

    @code {
        // Updating the whole row
        this.hierarchicalGrid.UpdateRow(newData, this.selectedCell.cellID.rowID);
    
        // Just a particular cell through the Tree Grid API
        this.hierarchicalGrid.UpdateCell(newData, this.selectedCell.cellID.rowID, this.selectedCell.column.field);
    
        // Directly using the cell `update` method
        this.selectedCell.Update(newData);
    
        // Directly using the row `update` method
        IgbRowType row = this.hierarchicalGrid.GetRowByKey(rowID);
        row.Update(newData);
    }
    razor

    Deleting data from the Hierarchical Grid

    DeleteRow 메서드는 PrimaryKey가 정의된 경우에만 지정된 행을 제거한다는 점을 기억하세요.

    @code {
        // Delete row through Grid API
        this.hierarchicalGrid.DeleteRow(this.selectedCell.cellID.rowID);
        // Delete row through row object
        IgbRowType row = this.hierarchicalGrid.GetRowByIndex(rowIndex);
        row.Del();
    }
    razor

    Cell Validation on Edit Event

    IgbHierarchicalGrid 편집 이벤트를 사용하여 사용자가 상호 작용하는 방식을 변경할 수 있습니다 IgbHierarchicalGrid.

    이 예에서는 CellEdit 이벤트에 바인딩하여 입력된 데이터를 기반으로 셀의 유효성을 검사합니다. 셀의 새 값이 사전 정의된 기준을 충족하지 않는 경우 이벤트를 취소하여 데이터 소스에 도달하지 못하게 합니다.

    가장 먼저 해야 할 일은 그리드의 이벤트에 바인딩하는 것입니다.

    <IgbHierarchicalGrid CellEditScript="HandleCellEdit" />
    razor

    CellEdit​ ​의 값이 커밋되려고 할 때마다 내보냅니다. CellEdit 정의에서 조치를 취하기 전에 특정 열을 확인해야 합니다.

    *** In JavaScript ***
    igRegisterScript("HandleCellEdit", (ev) => {
        const today = new Date();
        const column = event.detail.column;
    	if (column.field === 'Debut') {
    		if (event.detail.newValue > today.getFullYear()) {
    			event.detail.cancel = true;
    			alert('The debut date must be in the past!');
    		}
    	} else if (column.field === 'LaunchDate') {
    		if (event.detail.newValue > today) {
    			event.detail.cancel = true;
    			alert('The launch date must be in the past!');
    		}
    	}
    }, false);
    razor

    여기서는 두 개의 열을 검증합니다. 사용자가 아티스트의 데뷔 연도나 앨범의 출시 날짜를 변경하려고 하면 그리드에서는 오늘보다 이후의 날짜를 허용하지 않습니다.

    위의 유효성 검사가 적용된 IgbHierarchicalGrid 결과는 아래 데모에서 볼 수 있습니다.

    EXAMPLE
    DATA
    MODULES
    RAZOR
    JS
    CSS

    Styling

    사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.

    <IgbHierarchicalGrid Class="hierarchicalGrid"></IgbHierarchicalGrid>
    razor

    그런 다음 해당 클래스에 대한 관련 CSS 속성을 설정합니다.

    .hierarchicalGrid {
        --ig-grid-edit-mode-color: orange;
        --ig-grid-cell-editing-background: lightblue;
    }
    css

    Styling Example

    EXAMPLE
    DATA
    MODULES
    RAZOR
    CSS

    API References

    Additional Resources