import { isNullOrUndefined } from '@syncfusion/ej2-base' ; import { Column } from '../models/column' ; import { iterateArrayOrObject , isActionPrevent } from '../base/util' ; import * as events from '../base/constant' ; import { IGrid } from '../base/interface' ; /**
 * The `ShowHide` module is used to control column visibility.
 */ export class ShowHide { private parent : IGrid ; hidden constructor ( parent ) { this . parent = parent ; } param { string | string [ ] } columnName param { string } showBy return { void } public show ( columnName , showBy ? ) { let keys = this . getToggleFields ( columnName ) ; let columns = this . getColumns ( keys , showBy ) ; this . parent . notify ( events . tooltipDestroy , { module : 'edit' } ) ; columns . forEach ( ( value ) => { value . visible = true ; } ) ; this . setVisible ( columns ) ; } param { string | string [ ] } columnName param { string } hideBy return { void } public hide ( columnName , hideBy ? ) { let keys = this . getToggleFields ( columnName ) ; let columns = this . getColumns ( keys , hideBy ) ; this . parent . notify ( events . tooltipDestroy , { module : 'edit' } ) ; columns . forEach ( ( value ) => { value . visible = false ; } ) ; this . setVisible ( columns ) ; } private getToggleFields ( key ) { let finalized = [ ] ; if ( typeof key === 'string' ) { finalized = [ key ] ; } else { finalized = key ; } return finalized ; } private getColumns ( keys , getKeyBy ? ) { let columns = iterateArrayOrObject < Column , string > ( keys , ( key , index ) => { return iterateArrayOrObject < Column , Column > ( < Column [ ] > this . parent . getColumns ( ) , ( item , index ) => { if ( item [ getKeyBy ] === key ) { return item ; } return undefined ; } ) [ 0 ] ; } ) ; return columns ; } private param { Column [ ] } columns return { void } public setVisible ( columns ? ) { if ( isActionPrevent ( this . parent ) ) { this . parent . notify ( events . preventBatch , { instance : this , handler : this . setVisible , arg1 : columns } ) ; return ; } columns = isNullOrUndefined ( columns ) ? < Column [ ] > this . parent . getColumns ( ) : columns ; if ( this . parent . allowSelection && this . parent . getSelectedRecords ( ) . length ) { this . parent . clearSelection ( ) ; } this . parent . notify ( events . columnVisibilityChanged , columns ) ; if ( this . parent . columnQueryMode !== 'All' ) { this . parent . refresh ( ) ; } } }