import { ColumnBase } from './column-base' ; import { Column } from './column' ; import { Settings } from './settings' ; import { supportsStickyPosition } from '../../common/utils' ; export class ColumnModelGenerator { static actionColumn : ColumnBase = { name : 'action' , title : 'Row actions' , sortable : false , filter : false , frozen : true , resizeable : false , width : 40 , minWidth : 40 , formHidden : true , cellClass : 'action-cell' , headerCellClass : 'action-cell' , } ; static checkboxColumn : ColumnBase = { name : 'checkbox' , title : 'Checkbox selection' , sortable : false , filter : false , frozen : true , resizeable : false , width : 40 , minWidth : 40 , formHidden : true , cellClass : 'action-cell' , headerCellClass : 'action-cell' , } ; constructor ( private readonly settings ) { } createColumns ( columns ) { if ( this . settings . selectionMode ) { columns . unshift ( ColumnModelGenerator . checkboxColumn ) ; } return columns . map ( x => new Column ( x ) ) ; } prepareColumns ( columns ) { const frozenColumns = [ ] ; const scrollableColumns = [ ] ; let columnIndex = 0 ; const canSticky = supportsStickyPosition ( ) ; columns . forEach ( ( column ) => { column . frozen = column . frozen && canSticky ; this . setColumnSettings ( column ) ; if ( ! column . tableHidden ) { if ( column . frozen ) { frozenColumns . push ( column ) ; } else { scrollableColumns . push ( column ) ; } column . index = columnIndex ++ ; } } ) ; return [ ... frozenColumns , ... scrollableColumns ] ; } private setColumnSettings ( column ) { if ( this . settings . sortable === false ) { column . sortable = false ; } if ( this . settings . filter === false ) { column . filter = false ; } } }