Skip to content

Commit e87cede

Browse files
committed
Added ability to render add button in the footer
1 parent 031f971 commit e87cede

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Yii2 multiple input change log
55
---------------------
66

77
- #79 Added support for embedded MultipleInput widget (unclead, execut)
8+
- Enh: Added ability to render `add` button in the footer (unclead)
9+
- Enh: Improving for better work without ActiveForm (unclead)
810

911
1.2.19
1012
------

src/MultipleInput.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
*/
2323
class MultipleInput extends InputWidget
2424
{
25-
const POS_HEADER = 0;
26-
const POS_ROW = 1;
25+
const POS_HEADER = TableRenderer::POS_HEADER;
26+
const POS_ROW = TableRenderer::POS_ROW;
27+
const POS_FOOTER = TableRenderer::POS_FOOTER;
2728

2829
/**
2930
* @var ActiveRecordInterface[]|array[] input data

src/TabularInput.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
*/
2222
class TabularInput extends Widget
2323
{
24-
const POS_HEADER = 0;
25-
const POS_ROW = 1;
24+
const POS_HEADER = TableRenderer::POS_HEADER;
25+
const POS_ROW = TableRenderer::POS_ROW;
26+
const POS_FOOTER = TableRenderer::POS_FOOTER;
2627

2728
/**
2829
* @var array

src/assets/src/css/multiple-input.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
table.multiple-input-list {
1515
margin: 0;
1616
}
17-
table.multiple-input-list tr > td {
17+
table.multiple-input-list tbody tr > td {
1818
border: 0 !important;
1919
}
2020
table.multiple-input-list tr > td:first-child {

src/components/BaseRenderer.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
*/
2828
abstract class BaseRenderer extends Object
2929
{
30-
const POS_HEADER = 0;
31-
const POS_ROW = 1;
30+
const POS_HEADER = 'header';
31+
const POS_ROW = 'row';
32+
const POS_FOOTER = 'footer';
3233

3334
/**
3435
* @var string the ID of the widget
@@ -309,4 +310,20 @@ public function getUniqueHash()
309310
{
310311
return $this->uniqueHash;
311312
}
313+
314+
/**
315+
* @return bool
316+
*/
317+
protected function isAddButtonPositionHeader()
318+
{
319+
return $this->addButtonPosition === self::POS_HEADER;
320+
}
321+
322+
/**
323+
* @return bool
324+
*/
325+
protected function isAddButtonPositionFooter()
326+
{
327+
return $this->addButtonPosition === self::POS_FOOTER;
328+
}
312329
}

src/renderers/TableRenderer.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected function internalRender()
3333
}
3434

3535
$content[] = $this->renderBody();
36+
$content[] = $this->renderFooter();
3637

3738
$options = [];
3839
Html::addCssClass($options, 'multiple-input-list table table-condensed');
@@ -71,13 +72,26 @@ public function renderHeader()
7172
}
7273

7374
/**
74-
* @return bool
75+
* Renders the footer.
76+
*
77+
* @return string
7578
*/
76-
private function isAddButtonPositionHeader()
79+
public function renderFooter()
7780
{
78-
return $this->addButtonPosition === self::POS_HEADER;
81+
if (!$this->isAddButtonPositionFooter()) {
82+
return '';
83+
}
84+
85+
$cells = [];
86+
$cells[] = Html::tag('td', ' ', ['colspan' => count($this->columns)]);
87+
$cells[] = Html::tag('td', $this->renderAddButton(), [
88+
'class' => 'list-cell__button'
89+
]);
90+
91+
return Html::tag('tfoot', Html::tag('tr', implode("\n", $cells)));
7992
}
8093

94+
8195
/**
8296
* Check that at least one column has a header.
8397
*

0 commit comments

Comments
 (0)