Number Formatting with Active Form 1.2


#1

Hi Canvas team,

how do we format numbers in an active form with the new

<tm1-ui-rpt-row-cell
       tm1-row-data="{object}"
       tm1-column-no="{string}"
       tm1-column-elements="{string}"
       [tm1-picklist-disable-search="{boolean}"]
       [tm1-ui-class="{string}"]>
</tm1-ui-rpt-row-cell>

directive?

Cheers,

Marius


#2

Hi @mwirtz,

That should be through the accounting.js global settings in WEB-INF/pages/header.script.others.ftl.


Paul


#3

Hi @mwirtz

Here is the link to the accounting.js site as well - may be of interest also.

http://openexchangerates.github.io/accounting.js/

Regards,
Gerhard


#4

Hi guys,

thank you!

Actually in this case, I am not looking for a global solution. For us it would be most convenient to have a parameter in the directive that drives the formatting.

Regarding the header.script.others.ftl file.
I removed the comments and changes the settings. It doenst apply though :frowning:
Here is my content:

// accounting.js global format
// http://openexchangerates.github.io/accounting.js/#methods
// uncomment below for the settings to take effect

accounting.settings.currency.symbol = '';
accounting.settings.currency.format = {pos:'%v', neg:'(%v)', zero:'-'};
accounting.settings.currency.precision = 2;
accounting.settings.number.precision = 2;

It’s strange, when I debug those lines in the browser they are executed without doubt. But in the activeForm it’s still displayed without decimals. This is the code from our directive:

<tm1-ui-rpt-row-cell 
     tm1-row-data="rowData" 
     tm1-column-elements="{{page.years[0]}}">
</tm1-ui-rpt-row-cell>

Is this maybe a bug?

Cheers,

Marius


#5

Hi Marius,

You still can use combination of ng-hide=“true”, ng-model=“yourValue” and angular expression with filter {{ yourValue | formatNumber:2 }} at least as a temporary solution.

Regards,
Eugene


#6

Hi Eugene,

thanks for the help. I have tried that too.
But the tm1-ui-rpt-row-cell doesnt accept ng-model (at least for me) as a parameter.

Cheers,

Marius


#7

It doesn’t work for me either. And it wouldn’t work. Because for new directive tm1-ui-rpt-row-cell rowData looks like collection of methods:

it works for old style dbr. new directive doesn’t have ng-model parameter documented…
but you can use both directives in one active form. I tested this.

      <td class="text-right">
        <tm1-ui-dbr tm1-rpt-view-model="data" ng-hide="true" tm1-rpt-row-cell="rowData.getCell('Jul')" ng-model="page.testdata[$index]"></tm1-ui-dbr>
        {{page.testdata[$index] | formatNumber:0}}
      </td>

#8

Hi Marius,

I managed it worked with tm1-ui-rpt-row-cell. Just by refering to rowData.getCell(‘Jul’).value. you even no need to use ng-hide and ng-model.

 <tr ng-repeat="rowData in data.rows track by $index" ng-if="rowData.inPage">
        <td class="text-right" >
                     {{rowData.getCell('Jul').value | formatNumber:4}}
              <!-- <tm1-ui-rpt-row-cell
                                   ng-hide="true"  
                                   ng-model="data"
                                   tm1-row-data="rowData" 
                                   tm1-column-elements="Jul" >
                </tm1-ui-rpt-row-cell>  -->
          </td>
          <!-- .... -->
    </tr>

#9

Awesome! This is exactly what I needed. Thank you


#10

Does anybody knows how to get data of AF in that way I proposed before but If there are two dimensions in columns.
I tried {{ rowData.getCell('first dim element','second dim element').value }} but it doesn’t work.
Need it because I need to multiply value *-1 after.


#11

Hi @eugene,

Try it out with the following instead:

{{ rowData.getCell('first dim element,second dim element').value }} 


Paul


#12

thanks, Paul! just forked out and got the same result :slight_smile:
but I found that everything is low case in console. but it looks it works like case insensative
i.e {{ rowData.getCell('first dim element,second dim element').value }} == {{ rowData.getCell('First dim element,Second dim element').value }}. Am I right?


#13

Hi @eugene,

You mean:

{{ rowData.getCell('First dim element,Second dim element').value }}
AND 
{{ rowData.getCell('first dim element,second dim element').value }}

? If so, then yes. They should be both, case and space insensitive.


Paul


#14

yes. firstly copied wrong code).

Another question - how to pass a variable to rowData.getCell( ).value method?
I mean something like that {{ rowData.getCell( “{{someVariable}},actual” ).value
or {{ rowData.getCell( someVariable + ‘,actual’ ).value }}

both methods don’t work. Is it possible to pass a variable inside?

I found I can pass only one variable {{ rowData.getCell( someVariable ).value }}. So cannot put expression inside expression…


#15

I found a way.
/* JS /
$scope.concatIT = function(a,b){
var c = a+’,’+b;
return c;
}
/
html */
{{ rowData.getCell( concatIT(someVariable,‘Actual’) ).value }}


#16

Hi @eugene,

Had just tried it out and the second scenario you have should work. For example:

{{rowData.getCell('0' + values.month).value}}

Just need to ensure that your variable has an initial value. Otherwise, you might see some errors in the console.


Paul


#17

Yea, I see error in console as well. thanks for advice. works as well!


#18

Hi @eugene,

Great! Thanks for the update!


Paul


#19

but it looks function works faster. Anyway it doesn’t look like best practice, in most cases it should be resolved by using a different measure.:slight_smile: