Skip to content

Improvements for Tables, CRUDS and few other areas. - #277

Merged
romaninsh merged 2 commits into
developfrom
feature/cleanups2
Dec 4, 2017
Merged

Improvements for Tables, CRUDS and few other areas.#277
romaninsh merged 2 commits into
developfrom
feature/cleanups2

Conversation

@romaninsh

Copy link
Copy Markdown
Member

Tables are good for outputting data from a model, but sometimes you need to add that extra row, some sub-header or subtotal.

This adds example on how you can do that and adds two new hooks into table: beforeRow and afterRow

$table->template->appendHTML('SubHead', '<tr class="center aligned"><th colspan=2>This is sub-header, goes inside "thead" tag</th></tr>');

screen shot 2017-11-30 at 21 52 16

@romaninsh
romaninsh requested a review from DarkSide666 December 3, 2017 14:18
@codecov

codecov Bot commented Dec 3, 2017

Copy link
Copy Markdown

Codecov Report

Merging #277 into develop will decrease coverage by 0.09%.
The diff coverage is 90.9%.

Impacted file tree graph

@@             Coverage Diff              @@
##             develop     #277     +/-   ##
============================================
- Coverage      75.64%   75.54%   -0.1%     
- Complexity      1131     1132      +1     
============================================
  Files             63       63             
  Lines           2800     2691    -109     
============================================
- Hits            2118     2033     -85     
+ Misses           682      658     -24
Impacted Files Coverage Δ Complexity Δ
src/Table.php 86.82% <90.9%> (-0.13%) 82 <8> (+1)
src/jQuery.php 71.42% <0%> (-3.58%) 3% <0%> (ø)
src/FormField/CheckBox.php 80% <0%> (-1.82%) 6% <0%> (ø)
src/Message.php 66.66% <0%> (-1.76%) 8% <0%> (ø)
src/FormField/Generic.php 90% <0%> (-1.67%) 6% <0%> (ø)
src/Modal.php 41.02% <0%> (-1.66%) 32% <0%> (ø)
src/jsNotify.php 40% <0%> (-1.18%) 20% <0%> (ø)
src/Grid.php 79.41% <0%> (-1.15%) 28% <0%> (ø)
src/VirtualPage.php 75.6% <0%> (-1.14%) 24% <0%> (ø)
src/FormField/Money.php 88.88% <0%> (-1.12%) 6% <0%> (ø)
... and 42 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 693fc27...837abcb. Read the comment docs.

@DarkSide666 DarkSide666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is good update.

I don't see afterRow hook implementation. That would take away need to mess with model values in beforeRow hook to add row after current one.
On the other hand - that's another hook to call and we can work around need for it like you have shown in demo - by changing model values. Not nice workaround, but .... it works.

See few more review comments in code.

Comment thread demos/table2.php
$table->template->appendHTML('Body', '<tr class="center aligned"><td colspan=2>This goes above row with ID=2 ('.$table->current_row['action'].')</th></tr>');
} elseif ($table->current_id == 3) {
$table->renderRow();
$table->model->set(['action'=>'manually injected row after Tax', 'amount'=>0]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite hackish way to do this, but it works of course :)

Comment thread src/Table.php
return View::renderView();
}

public function renderRow()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments added for this method.

Comment thread src/Table.php
}
$field = $this->model->hasElement($name);
foreach ($columns as $column) {
if (!method_exists($column, 'getHTMLTags')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please simplify this to:

if (method_exists($column, 'getHTMLTags')) {
    $html_tags = array_merge($column->getHTMLTags($this->model, $field), $html_tags);
}

No need for negation and continue; here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont understand, please propose through a separate PR.

Comment thread src/Table.php
$rows = 0;
foreach ($this->model as $this->current_id => $tmp) {
$this->current_row = $this->model->get();
$this->hook('beforeRow');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hook should be after updateTotals(), because if you change model values (like in example where you add row after current one), then totals will be messed up too.
On the other hand - sometimes it can be useful to add some additional conditions on updateTotals().

Also i think it would be great if we add ability to return false from beforeRow hook and in that case row will not be rendered (and not added to totals) at all. In that case it is good to have hook before updateTotals().

@romaninsh romaninsh changed the title More control over table rows Improvements for Tables, CRUDS and few other areas. Dec 4, 2017
@romaninsh
romaninsh merged commit 3494ad7 into develop Dec 4, 2017
@romaninsh
romaninsh deleted the feature/cleanups2 branch December 4, 2017 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants