Conversation
|
Need to add tests for all different kinds of totals. |
|
wow relally good PR but do I have to write all the docs myself again ? 👍 |
|
Tomorrow I will add one more feature there. I have it now (idea) written down on paper but to sleepy to implement it now :) |
|
something that came to my mind was ability to specify 'name' for the total rows, e.g. addTotals('row2'), then it is safer for you to modify it. Obviously should be optional. |
|
Also it would be better to move all that totals functionality outside Table in separate class Totals.
|
demos/table.php
Outdated
| return strlen($value) > strlen($total) ? $value : $total; | ||
| }, | ||
| 'title'=>function ($total, $model) { | ||
| return "Shortes is: ".$total; |
There was a problem hiding this comment.
longest not shortest
docs/table.rst
Outdated
| $table->addField('no'); | ||
|
|
||
| $table->addHook('beforeRow', function($table)) { | ||
| $table->model['no'] = @++$t->npk; |
There was a problem hiding this comment.
what is $t? Probably $table->nkp, right?
docs/table.rst
Outdated
| `update` can be string. Supported built-ins are: | ||
|
|
||
| - min | ||
| - inc |
docs/table.rst
Outdated
| - avg | ||
|
|
||
| You can use a callable which gives you an option to perform update yourself. Also, make note that `inc` | ||
| will ONLY increment when value of the column it's associated with is not empty. If you need to get |
There was a problem hiding this comment.
please be more specific what "empty" means here. Is 0 empty? Is empty string empty? Or is it just null. I think that 0 is not empty, but empty string is empty.
docs/table.rst
Outdated
| reference other fields too. A benefit for using template is that type formatting is done automatically | ||
| for you. | ||
|
|
||
| If `format` set to `null` or omitted then default action will be used which is to display totals only |
There was a problem hiding this comment.
I didn't understand this sentence.
docs/table.rst
Outdated
| // $total is previous value | ||
| // $value is value of the column | ||
| // $model will be loaded to current column | ||
| } |
There was a problem hiding this comment.
please add return statement here to make things clearer
src/Table.php
Outdated
| case 'sum': | ||
| $this->totals[$key] += $this->model[$key]; | ||
| // set initial value | ||
| $t[$key] = ($t[$key] === null ? 0 : $t[$key]); |
There was a problem hiding this comment.
looks like you over-engineer here, how about this
$t[$key] = (int)$t[$key] + $this->model[$key];
There was a problem hiding this comment.
actually might be tricky because of (int) and (float)
There was a problem hiding this comment.
There was a problem hiding this comment.
ok, how about this:
$t[$key] = $t[$key]===null ? 0 : ($t[$key] + $this->model[$key]);
src/Table.php
Outdated
| // should return new total value (for example, current value + current field value) | ||
| // NOTE: Keep in mind, that current total value initially will be null ! | ||
| if (is_callable($f)) { | ||
| $t[$key] = call_user_func_array($f, [$t[$key], $this->model[$key], $key, $this]); |
There was a problem hiding this comment.
no change needed, but just note on the existence of http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.invoke
d43f6e4 to
d34d398
Compare
|
I have rebased 56da26e 1:1 and simplified the history as much as possible (by squashing CS fixer for example) into d34d398. The diff shows zero changes. Then I have reverted the changed file paths (files) on the latest develop and rebased the changes again (now with paths matching the current develop): all original changed: c75b7ae...d34d398 |
d34d398 to
4f7b418
Compare
19f7999 to
fe8a82f
Compare
fe8a82f to
bc2c0e5
Compare
* add ability to add multiple total plans.
* few other fixes
bc2c0e5 to
e53fa7b
Compare
|
Hi @DarkSide666, in my post above there is a link to view the real diff - what features/fixes are missing and can you rebase them on the latest develop? |
Total support in Grid is currently quite basic, implementing ability to add up numeric values, define per-column strategies and format the footer.
This PR offers many enhancements:
Ability to add multiple Total lines
Sometimes you would want to define multiple total lines, for instance - SubTotals and Totals. They will be increased simultaneously, but will output in 2 separate lines. They will also have separate strategy.
However SubTotals need ability to be "inserted" multiple times too, which we can implement using hook beforeRow (#277).
Advanced calculation strategies
Here for the data that contains various dates, we find and display date range in the bottom: "1 Jul - 20 Aug"