@@ -35,34 +35,34 @@ export default class Sample extends React.Component<any, any> {
3535 } ;
3636 protected columns = [
3737 {
38- key : 'id' ,
38+ field : 'id' ,
3939 hidden : true ,
40- headerText : 'ID'
40+ header : 'ID'
4141 } ,
4242 {
43- key : 'name' ,
44- headerText : 'Product Name'
43+ field : 'name' ,
44+ header : 'Product Name'
4545 } ,
4646 {
47- key : 'price' ,
48- headerText : 'Price' ,
49- type : 'number' ,
47+ field : 'price' ,
48+ header : 'Price' ,
49+ dataType : 'number' ,
5050 cellTemplate : this . format
5151 } ,
5252 {
53- key : 'sold' ,
54- type : 'number' ,
55- headerText : 'Units sold'
53+ field : 'sold' ,
54+ dataType : 'number' ,
55+ header : 'Units sold'
5656 } ,
5757 {
58- key : 'total' ,
59- headerText : 'Total sold' ,
58+ field : 'total' ,
59+ header : 'Total sold' ,
6060 cellTemplate : this . format
6161 } ,
6262 {
63- key : 'rating' ,
64- type : 'number' ,
65- headerText : 'Customer rating' ,
63+ field : 'rating' ,
64+ dataType : 'number' ,
65+ header : 'Customer rating' ,
6666 cellTemplate : ( params : any ) => {
6767 const rating = document . createElement ( 'igc-rating' ) ;
6868 rating . setAttribute ( 'readonly' , '' ) ;
@@ -86,25 +86,41 @@ export default class Sample extends React.Component<any, any> {
8686 if ( this . gridRef . current ) {
8787 const data : ProductInfo [ ] = this . dataService . generateProducts ( 50 ) ;
8888
89- this . gridRef . current . columns = this . columns ;
89+ // Set cellTemplates programmatically for columns that need them
90+ const priceCol = this . gridRef . current . columns . find ( ( c : any ) => c . field === 'price' ) ;
91+ if ( priceCol && this . columns . find ( col => col . field === 'price' ) ?. cellTemplate ) {
92+ priceCol . cellTemplate = this . format ;
93+ }
94+
95+ const totalCol = this . gridRef . current . columns . find ( ( c : any ) => c . field === 'total' ) ;
96+ if ( totalCol && this . columns . find ( col => col . field === 'total' ) ?. cellTemplate ) {
97+ totalCol . cellTemplate = this . format ;
98+ }
99+
100+ const ratingCol = this . gridRef . current . columns . find ( ( c : any ) => c . field === 'rating' ) ;
101+ const ratingColDef = this . columns . find ( col => col . field === 'rating' ) ;
102+ if ( ratingCol && ratingColDef ?. cellTemplate ) {
103+ ratingCol . cellTemplate = ratingColDef . cellTemplate ;
104+ }
105+
90106 this . gridRef . current . data = data ;
91107 }
92108 }
93109
94110 toggleFormatters ( checked : boolean ) {
95111 if ( this . gridRef . current ) {
96112 this . gridRef . current . updateColumns (
97- [ 'price' , 'total' ] . map ( ( key ) => ( {
98- key ,
113+ [ 'price' , 'total' ] . map ( ( field ) => ( {
114+ field ,
99115 cellTemplate : checked ? this . format : undefined ,
100116 } ) )
101117 ) ;
102118 }
103119 }
104120
105- toggleColumnProperty ( columnKey : string , property : string , value : boolean ) {
121+ toggleColumnProperty ( columnField : string , property : string , value : boolean ) {
106122 if ( this . gridRef . current ) {
107- this . gridRef . current . updateColumns ( { key : columnKey , [ property ] : value } ) ;
123+ this . gridRef . current . updateColumns ( { field : columnField , [ property ] : value } ) ;
108124 }
109125 }
110126
@@ -124,31 +140,31 @@ export default class Sample extends React.Component<any, any> {
124140 < IgrButton variant = "outlined" > < span > Column Properties</ span > </ IgrButton >
125141 </ div >
126142 { this . columns . map ( ( column : any ) => (
127- < IgrDropdownItem key = { column . key } >
143+ < IgrDropdownItem key = { column . field } >
128144 < div className = "config" >
129- < span className = "config-key" > { column . headerText } </ span >
145+ < span className = "config-key" > { column . header } </ span >
130146 < IgrCheckbox
131147 labelPosition = "before"
132148 checked = { ! column . hidden }
133- onChange = { ( e : any ) => this . toggleColumnProperty ( column . key , 'hidden' , ! e . target . checked ) } >
149+ onChange = { ( e : any ) => this . toggleColumnProperty ( column . field , 'hidden' , ! e . target . checked ) } >
134150 Hidden
135151 </ IgrCheckbox >
136152 < IgrCheckbox
137153 labelPosition = "before"
138154 checked = { column . resizable !== false }
139- onChange = { ( e : any ) => this . toggleColumnProperty ( column . key , 'resizable' , e . target . checked ) } >
155+ onChange = { ( e : any ) => this . toggleColumnProperty ( column . field , 'resizable' , e . target . checked ) } >
140156 Resizable
141157 </ IgrCheckbox >
142158 < IgrCheckbox
143159 labelPosition = "before"
144- checked = { column . filter === true }
145- onChange = { ( e : any ) => this . toggleColumnProperty ( column . key , 'filter ' , e . target . checked ) } >
160+ checked = { column . filterable === true }
161+ onChange = { ( e : any ) => this . toggleColumnProperty ( column . field , 'filterable ' , e . target . checked ) } >
146162 Filter
147163 </ IgrCheckbox >
148164 < IgrCheckbox
149165 labelPosition = "before"
150- checked = { column . sort === true }
151- onChange = { ( e : any ) => this . toggleColumnProperty ( column . key , 'sort ' , e . target . checked ) } >
166+ checked = { column . sortable === true }
167+ onChange = { ( e : any ) => this . toggleColumnProperty ( column . field , 'sortable ' , e . target . checked ) } >
152168 Sort
153169 </ IgrCheckbox >
154170 </ div >
@@ -167,7 +183,17 @@ export default class Sample extends React.Component<any, any> {
167183 </ IgrSwitch >
168184 </ section >
169185 < div className = "grid-lite-wrapper" >
170- < igc-grid-lite ref = { this . gridRef } id = "grid-lite" > </ igc-grid-lite >
186+ < igc-grid-lite ref = { this . gridRef } id = "grid-lite" >
187+ { this . columns . map ( ( column : any ) => (
188+ < igc-grid-lite-column
189+ key = { column . field }
190+ field = { column . field }
191+ header = { column . header }
192+ data-type = { column . dataType }
193+ hidden = { column . hidden }
194+ > </ igc-grid-lite-column >
195+ ) ) }
196+ </ igc-grid-lite >
171197 </ div >
172198 </ div >
173199 ) ;
0 commit comments