@@ -57,6 +57,14 @@ public function getPart($key) {
5757 return $ this ->content [$ key ];
5858 }
5959
60+ protected function _getFirstPart (){
61+ if (isset ($ this ->content ["thead " ])){
62+ return $ this ->content ["thead " ];
63+ }
64+ return $ this ->content ["tbody " ];
65+ }
66+
67+
6068 /**
6169 * Returns/create eventually the body of the table
6270 * @return HtmlTableContent
@@ -374,22 +382,34 @@ public function setActiveRowSelector($class="active",$event="click",$multiple=fa
374382 }
375383
376384 public function hideColumn ($ colIndex ){
377- if ($ this ->hasPart ( "thead " )){
378- $ this ->getHeader () ->hideColumn ($ colIndex );
385+ if (isset ( $ this ->content [ "thead " ] )){
386+ $ this ->content [ " thead " ] ->hideColumn ($ colIndex );
379387 }
380- $ this ->getBody () ->hideColumn ($ colIndex );
381- if ($ this ->hasPart ( "tfoot " )){
382- $ this ->getFooter () ->hideColumn ($ colIndex );
388+ $ this ->content [ " tbody " ] ->hideColumn ($ colIndex );
389+ if (isset ( $ this ->content [ "tfoot " ] )){
390+ $ this ->content [ " tfoot " ] ->hideColumn ($ colIndex );
383391 }
384392 return $ this ;
385393 }
386-
394+
387395 public function setColWidth ($ colIndex ,$ width ){
388- if ($ this ->hasPart ("thead " )){
389- $ this ->getHeader ()->getCell (0 , $ colIndex )->setWidth ($ width );
390- }else {
391- if ($ this ->getBody ()->count ()>0 )
392- $ this ->getBody ()->getCell (0 , $ colIndex )->setWidth ($ width );
396+ $ part =$ this ->_getFirstPart ();
397+ if ($ part !==null && $ part ->count ()>0 )
398+ $ part ->getCell (0 , $ colIndex )->setWidth ($ width );
399+ return $ this ;
400+ }
401+
402+ public function setColWidths ($ widths ){
403+ $ part =$ this ->_getFirstPart ();
404+ if ($ part !==null && $ part ->col ()>0 ){
405+ $ count =$ part ->getColCount ();
406+ if (!\is_array ($ widths )){
407+ $ widths =\array_fill (0 , $ count , $ widths );
408+ }
409+ $ max =\min (\sizeof ($ widths ),$ count );
410+ for ($ i =0 ;$ i <$ max ;$ i ++){
411+ $ part ->getCell (0 , $ i )->setWidth ($ widths [$ i ]);
412+ }
393413 }
394414 return $ this ;
395415 }
0 commit comments