Skip to content

Commit 4bf1722

Browse files
committed
setColWidth for dataTable
1 parent 872df95 commit 4bf1722

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

Ajax/semantic/html/collections/table/HtmlTable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,14 @@ public function hideColumn($colIndex){
383383
}
384384
return $this;
385385
}
386+
387+
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);
393+
}
394+
return $this;
395+
}
386396
}

Ajax/semantic/html/content/HtmlGridCol.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Ajax\semantic\html\base\HtmlSemDoubleElement;
66
use Ajax\semantic\html\base\constants\Wide;
77
use Ajax\semantic\html\base\traits\TextAlignmentTrait;
8-
use Ajax\semantic\html\base\constants\Direction;
98
use Ajax\semantic\html\elements\HtmlDivider;
109

1110
/**

Ajax/semantic/html/content/table/HtmlTD.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Ajax\semantic\html\base\constants\State;
99
use Ajax\semantic\html\base\traits\TableElementTrait;
1010
use Ajax\semantic\html\elements\html5\HtmlLink;
11+
use Ajax\semantic\html\base\constants\Wide;
1112

1213
class HtmlTD extends HtmlSemDoubleElement {
1314
use TextAlignmentTrait,TableElementTrait;
@@ -111,4 +112,12 @@ public function setSelectable($href="#") {
111112
}
112113
return $this->addToProperty("class", "selectable");
113114
}
115+
116+
public function setWidth($width){
117+
if (\is_int($width)) {
118+
$width=Wide::getConstants()["W" . $width];
119+
}
120+
$this->addToPropertyCtrl("class", $width, Wide::getConstants());
121+
return $this->addToPropertyCtrl("class", "wide", array ("wide" ));
122+
}
114123
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class DataTable extends Widget {
3838
protected $_rowClass="";
3939
protected $_sortable;
4040
protected $_hiddenColumns;
41+
protected $_colWidths;
4142

4243

4344
public function __construct($identifier,$model,$modelInstance=NULL) {
@@ -120,6 +121,12 @@ public function compile(JsUtils $js=NULL,&$view=NULL){
120121
$this->_compileForm();
121122
if(isset($this->_hiddenColumns))
122123
$this->_hideColumns();
124+
if(isset($this->_colWidths)){
125+
foreach ($this->_colWidths as $colIndex=>$width){
126+
$table->setColWidth($colIndex,$width);
127+
}
128+
}
129+
123130
$this->_generated=true;
124131
}
125132
return parent::compile($js,$view);
@@ -425,5 +432,15 @@ public function hideColumn($colIndex){
425432
$this->_hiddenColumns[]=$colIndex;
426433
return $this;
427434
}
435+
436+
public function setColWidth($colIndex,$width){
437+
$this->_colWidths[$colIndex]=$width;
438+
return $this;
439+
}
440+
public function setColWidths($_colWidths) {
441+
$this->_colWidths = $_colWidths;
442+
return $this;
443+
}
444+
428445

429446
}

0 commit comments

Comments
 (0)