1- import { Palette , PropertyExt , Field } from "@hpcc-js/common" ;
1+ import { Palette , PropertyExt , Field , Utility } from "@hpcc-js/common" ;
22import { hashSum } from "@hpcc-js/util" ;
33import { format as d3Format } from "d3-format" ;
44import { select as d3Select } from "d3-selection" ;
@@ -155,9 +155,12 @@ export class Table extends Common {
155155 this . guessWidth ( column . children , sampleData ) ;
156156 } else {
157157 column . width = data . reduce ( ( prevVal : number , row ) => {
158- const cell = ( "" + row [ column . idx ] ) . trim ( ) ;
159- return Math . max ( prevVal , this . textSize ( cell ) . width ) ;
160- } , this . textSize ( "" + column . label , undefined , undefined , true ) . width + sortablePadding ) + 8 ; // +12 for the sort icon, +8 for the cell padding.
158+ let cell = ( "" + row [ column . idx ] ) . trim ( ) ;
159+ if ( this . renderHtml ( ) && cell [ 0 ] === "<" ) {
160+ cell = Utility . removeHTMLFromString ( cell ) ;
161+ }
162+ return Math . max ( prevVal , this . textSize ( cell , this . columnWidthAutoFontName ( ) , this . columnWidthAutoFontSize ( ) ) . width ) ;
163+ } , this . textSize ( "" + column . label , this . columnWidthAutoFontName ( ) , this . columnWidthAutoFontSize ( ) , true ) . width + sortablePadding ) + 8 ; // +12 for the sort icon, +8 for the cell padding.
161164 }
162165 }
163166 }
@@ -174,8 +177,8 @@ export class Table extends Common {
174177 this . _columns = this . _store . columns ( this . sortable ( ) , this . formatterFunc ( ) , this . renderCellFunc ( ) ) ;
175178 switch ( this . columnWidth ( ) ) {
176179 case "auto" :
177- const tenRows = this . data ( ) . filter ( ( row , idx ) => idx < 10 ) ;
178- this . guessWidth ( this . _columns , tenRows ) ;
180+ const sampleRows = this . data ( ) . filter ( ( row , idx ) => idx < this . columnWidthAutoSampleSize ( ) ) ;
181+ this . guessWidth ( this . _columns , sampleRows ) ;
179182 break ;
180183 }
181184 const columns = this . columns ( ) ;
@@ -238,9 +241,18 @@ Table.prototype._class += " dgrid_Table";
238241export interface Table {
239242 columnWidth ( ) : "auto" | "none" ;
240243 columnWidth ( _ : "auto" | "none" ) : this;
244+ columnWidthAutoSampleSize ( ) : number ;
245+ columnWidthAutoSampleSize ( _ : number ) : this;
246+ columnWidthAutoFontName ( ) : string ;
247+ columnWidthAutoFontName ( _ : string ) : this;
248+ columnWidthAutoFontSize ( ) : number ;
249+ columnWidthAutoFontSize ( _ : number ) : this;
241250 columnFormats ( ) : ColumnFormat [ ] ;
242251 columnFormats ( _ : ColumnFormat [ ] ) : this;
243252}
244253
245254Table . prototype . publish ( "columnWidth" , "auto" , "set" , "Default column width" , [ "auto" , "none" ] ) ;
255+ Table . prototype . publish ( "columnWidthAutoSampleSize" , 10 , "number" , "Number of rows to sample for auto column width" ) ;
256+ Table . prototype . publish ( "columnWidthAutoFontName" , "Verdana" , "string" , "Font name for auto column width calculation" ) ;
257+ Table . prototype . publish ( "columnWidthAutoFontSize" , 12 , "number" , "Font size for auto column width calculation" ) ;
246258Table . prototype . publish ( "columnFormats" , [ ] , "propertyArray" , "Source Columns" , null , { autoExpand : ColumnFormat } ) ;
0 commit comments