React Tree Grid 조건부 스타일링

    트리 그리드의 Ignite UI for React 조건부 스타일 지정 기능을 사용하면 행 또는 셀 수준에서 사용자 지정 스타일을 지정할 수 React. 이 IgrTreeGrid 조건부 스타일 기능은 특정 조건을 충족하는 데이터를 시각적으로 강조하거나 강조 표시하는 데 사용되어 사용자가 그리드 내에서 중요한 정보나 추세를 쉽게 식별할 수 있도록 합니다.

    트리 그리드 조건부 행 스타일 지정

    IgrTreeGrid Ignite UI for React의 구성 요소는 다음 두 가지 방법을 제공합니다. 행의 조건부 스타일 지정 사용자 지정 규칙을 기반으로 합니다.

    이 주제에서는 두 가지 모두에 대해 더 자세히 다룰 것입니다.

    행 클래스 사용

    입력을 설정하고 사용자 지정 규칙을 정의하여 조건부로 행의 IgrTreeGrid​ ​rowClasses 스타일을 지정할 수 있습니다.

    <IgrTreeGrid id="grid" height="600px" width="100%" rowClasses={rowClasses}>
    </IgrTreeGrid>
    tsx

    rowClasses 입력은 키-값 쌍을 포함하는 객체 리터럴을 허용합니다. 여기서 키는 CSS 클래스의 이름이고 값은 부울 또는 부울 값을 반환하는 콜백 함수입니다.

    const rowClasses = {
        activeRow: (row: IgrRowType) => row.index === 0
    }
    tsx
    .activeRow {
        border: 2px solid #fc81b8;
        border-left: 3px solid #e41c77;
    }
    css

    데모

    EXAMPLE
    DATA
    TSX
    CSS

    이 샘플이 마음에 드시나요? Ignite UI for React 전체에 액세스하고 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.

    행 스타일 사용

    이 컨트롤은 IgrTreeGrid 데이터 행의 rowStyles 조건부 스타일을 허용하는 속성을 노출합니다. 이와 rowClasses 유사하게, 키는 스타일 속성이고 값은 평가를 위한 표현식인 개체 리터럴을 허용합니다. 또한 조건 없이 일반 스타일을 적용할 수 있습니다.

    The callback signature for both rowStyles and rowClasses is:

    (row: IgrRowType) => boolean
    tsx

    스타일을 정의해 보겠습니다.

    const rowStyles = {
        'background': (row: IgrRowType) => row.data['Title'] === 'CEO' ? '#6c757d' :
            row.data['Title'].includes('President') ?'#adb5bd' :
            row.data['Title'].includes('Director') ? '#ced4da' :
            row.data['Title'].includes('Manager') ? '#dee2e6' :
            row.data['Title'].includes('Lead') ? '#e9ecef' :
            row.data['Title'].includes('Senior') ? '#f8f9fa' : null,
        'border-left': (row: IgrRowType) => row.data['Title'] === 'CEO' || row.data['Title'].includes('President') ? '2px solid' : null,
        'border-color': (row: IgrRowType) => row.data['Title'] === 'CEO' ? '#495057' : null,
        'color': (row: IgrRowType) => row.data['Title'] === 'CEO' ? '#fff' : null
    };
    tsx
    <IgrTreeGrid autoGenerate={true} primaryKey="ID" foreignKey="ParentID" data={data} rowStyles={rowStyles}>
    </IgrTreeGrid>
    tsx

    데모

    EXAMPLE
    DATA
    TSX
    CSS

    트리 그리드 조건부 셀 스타일 지정

    Ignite UI for React | CTA 배너

    개요

    IgrTreeGrid Ignite UI for React의 구성 요소는 다음 두 가지 방법을 제공합니다. 셀의 조건부 스타일 지정 사용자 지정 규칙을 기반으로 합니다.

    • IgrColumn 입력 cellClasses 키-값 쌍을 포함하는 객체 리터럴로 설정합니다. 키는 CSS 클래스의 이름이고 값은 부울 또는 부울 값을 반환하는 콜백 함수입니다. 그 결과 셀의 편리한 소재 스타일링이 이루어졌습니다.

    셀 클래스 사용

    를 설정하여 조건부로 셀의 IgrTreeGrid 스타일을 지정할 수 있습니다. IgrColumn ​ ​cellClasses 사용자 지정 규칙을 입력하고 정의합니다.

    <IgrColumn field="UnitPrice" header="Unit Price" dataType="currency" cellClasses={unitPriceCellClasses}>
    </IgrColumn>
    tsx

    cellClasses 입력은 키-값 쌍을 포함하는 객체 리터럴을 허용합니다. 여기서 키는 CSS 클래스의 이름이고 값은 부울 또는 부울 값을 반환하는 콜백 함수입니다.

    const upPriceCondition = (rowData: any, columnKey: any): boolean => {
        return rowData[columnKey] > 5;
    }
    
    const downPriceCondition = (rowData: any, columnKey: any): boolean => {
        return rowData[columnKey] <= 5;
    }
    
    const unitPriceCellClasses = {
        downPrice: downPriceCondition,
        upPrice: upPriceCondition
    };
    tsx
    .upPrice {
        color: red !important;
    }
    
    .downPrice {
        color: green !important;
    }
    css

    데모

    EXAMPLE
    DATA
    TSX
    CSS

    • 키가 스타일 속성이고 값이 평가용 표현식인 객체 리터럴을 허용하는 IgrColumn 입력 cellStyles 사용합니다.

    이제 cellStylescellClasses에 대한 콜백 서명이 다음으로 변경되었습니다.

    (rowData: any, columnKey: string, cellValue: any, rowIndex: number) => boolean
    ts

    셀 스타일 사용

    열은 열 셀의 조건부 스타일 지정을 허용하는 cellStyles 속성을 노출합니다. cellClasses와 유사하게 키가 스타일 속성이고 값이 평가용 표현식인 객체 리터럴을 허용합니다. 또한 아무런 조건 없이 일반 스타일링을 쉽게 적용할 수 있습니다.

    스타일을 정의해 보겠습니다.

    const webTreeGridCellStyles = {
        background: (rowData, columnKey, cellValue, rowIndex) => rowIndex % 2 === 0 ? "#EFF4FD" : null,
        color: (rowData, columnKey, cellValue, rowIndex) => {
            if (columnKey === "UnitPrice") {
                if (cellValue > 10) return "#dc3545";
                if (cellValue < 5) return "#28a745";
                if (cellValue >= 5 && cellValue <= 10) return "#17a2b8";
            }
        }
    }
    tsx
    <IgrColumn cellStyles={webTreeGridCellStyles}></IgrColumn>
    tsx

    데모

    EXAMPLE
    DATA
    TSX
    CSS

    알려진 문제 및 제한 사항

    • 동일한 조건(다른 열의)에 바인딩된 셀이 있고 하나의 셀이 업데이트되는 경우 조건이 충족되면 다른 셀은 새 값을 기반으로 업데이트되지 않습니다.
    const backgroundClasses = {
        myBackground: (rowData: any, columnKey: string) => {
            return rowData.Col2 < 10;
        }
    };
    
    const editDone = (event: IgrGridEditEventArgs) => {
        backgroundClasses = {...backgroundClasses};
    }
    
    <IgrTreeGrid id="grid1" height="500px" width="100%" onCellEdit={editDone}>
      <IgrColumn id="Col1" field="Col1" dataType="number" cellClasses={backgroundClasses}></IgrColumn>
      <IgrColumn id="Col2" field="Col2" dataType="number" editable={true} cellClasses={backgroundClasses}></IgrColumn>
      <IgrColumn id="Col3" field="Col3" header="Col3" dataType="string" cellClasses={backgroundClasses}></IgrColumn>
    </IgrTreeGrid>
    tsx

    API 참조

    추가 리소스

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.