React Tree Grid 상태 지속성

    React 트리 그리드의 Ignite UI for React 상태 지속성을 통해 개발자는 그리드 상태를 쉽게 저장하고 복원할 수 있습니다. React IgrGridState​ ​IgrTreeGrid에 적용되면 개발자가 모든 시나리오에서 상태 유지를 달성하는 데 사용할 수 있는 메서드 GetStateAsString​ ​ApplyStateFromString​ ​ApplyStateGetState 메서드가 노출됩니다.

    Supported Features

    IgrGridState 지시문은 다음 기능의 상태 저장 및 복원을 지원합니다.

    • Sorting
    • Filtering
    • 고급 필터링
    • 페이징
    • CellSelection
    • 행 선택
    • ColumnSelection
    • RowPinning
    • 확장
    • 그룹화 기준
    • Columns
      • Multi column headers
      • 열 순서
      • Column properties defined by the IColumnState interface.

    Usage

    이 메서드는 getState 모든 상태 정보를 포함하는 개체의 그리드 상태를 IgrGridStateInfo 반환합니다. 저장하려면 추가 단계가 필요할 수 있습니다.

    직렬화 된 JSON 문자열을 GetStateAsString 반환하므로 개발자는 이를 가져와 모든 데이터 저장소(데이터베이스, 클라우드, 브라우저 localStorage 등)에 저장할 수 있습니다.

    개발자는 기능 이름이 있는 배열을 인수로 전달하여 특정 기능에 대한 상태만 가져오도록 선택할 수 있습니다. 빈 배열은 기본 상태 옵션을 사용하게 됩니다.

    <IgrTreeGrid>
        <IgrGridState ref={(ref) => { gridState = ref; }}></IgrGridState>
    </IgrTreeGrid>
    tsx
    // get an `IgrGridStateInfo` object, containing all features original state objects, as returned by the grid public API
    const state: IgrGridStateInfo = gridState.getState([]);
    
    // get all features` state in a serialized JSON string
    const stateString: string = gridState.getStateAsString([]);
    
    // get the sorting and filtering expressions
    const sortingFilteringStates: IgrGridStateInfo = gridState.getState(['sorting', 'filtering']);
    tsx

    ApplyState- 이 메서드는 객체를 인수로 받아들이고 IgrGridStateInfo 객체 또는 지정된 기능에서 찾은 각 기능의 상태를 두 번째 인수로 복원합니다.

    ApplyStateFromString- 이 메서드는 직렬화된 JSON 문자열을 인수로 허용하고 JSON 문자열에 있는 각 기능 또는 지정된 기능의 상태를 두 번째 인수로 복원합니다.

    gridState.applyState(gridState, []);
    gridState.applyStateFromString(gridStateString, []);
    gridState.applyState(sortingFilteringStates, [])
    tsx

    객체는 Options 인터페이스를 구현 IgrGridStateOptions 합니다, 즉, 특정 기능의 이름인 모든 키에 대해 이 기능 상태가 추적되는지 여부를 나타내는 부울 값이 있습니다. GetState / GetStateAsString methods는 이러한 기능의 상태를 반환된 값에 넣지 않으며 ApplyState / ApplyStateFromString methods는 해당 기능의 상태를 복원하지 않습니다.

    <IgrGridState options={{ cellSelection: false, sorting: false }}></IgrGridState>
    tsx

    사용하기 쉬운 단일 지점 API를 사용하면 몇 줄의 코드로 전체 상태 유지 기능을 얻을 수 있습니다. 아래에서 코드를 복사하여 붙여 넣 으십시오 - 사용자가 현재 페이지를 떠날 때마다 브라우저 LocalStorage 개체에 그리드 상태를 저장합니다. 사용자가 기본 페이지로 돌아갈 때마다 그리드 상태가 복원됩니다. 더 이상 원하는 데이터를 얻기 위해 매번 복잡한 고급 필터링 및 정렬 표현식을 구성할 필요가 없습니다 - 한 번만 수행하고 아래 코드가 사용자를 위해 나머지 작업을 수행하도록 합니다.

    <IgrTreeGrid rendered={restoreGridState}>
        <IgrGridState ref={(ref) => { gridState = ref; }}></IgrGridState>
    </IgrTreeGrid>
    tsx
    useEffect(() => {
        restoreGridState();
        window.addEventListener('beforeunload', saveGridState);
        return () => {
          window.removeEventListener('beforeunload', saveGridState);
        }
    }, []);
    
    // Using methods that work with IgrGridStateInfo object.
    function saveGridState() {
        const state = gridState.getState([]);
        window.localStorage.setItem('grid-state', JSON.stringify(state));
    }
    
    function restoreGridState() {
        const state = window.localStorage.getItem('grid-state');
        if (state) {
            gridState.applyState(JSON.parse(state), []);
        }
    }
    
    //Or using string alternative methods.
    function saveGridState() {
        const state = gridState.getStateAsString([]);
        window.localStorage.setItem('grid-state', state);
    }
    
    function restoreGridState() {
        const state = window.localStorage.getItem('grid-state');
        if (state) {
            gridState.applyStateFromString(state, []);
        }
    }
    tsx
    Ignite UI for React | CTA Banner

    Demo

    EXAMPLE
    DATA
    TSX
    CSS

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

    Limitations