Suppress zero value


#1

Hi all,

I would like to create a suppress zero value but not necessary for an active form in Cavas but for a normal table. Is there a way to make it?
thanks
S.


#2

Hi @sschreurs,

Here are some of the ways you can go about it:

  1. Use MDX (filter dimension by cube data) with tm1-ui-element-list, and use the result of the element list to drive your table

  2. See examples ‘Sortable, Filtered Table’ and ‘Data Entry Template’

  3. Use $tm1Ui.cellsetGet and pass in a bunch of DBR request to get your data, then create an array with non-zero values then use this as the basis for your rows on your table.

I am sure there are more ways other than the above. So feel free to add here other methodologies that works or other variations you have used.

Cheers!


Paul


#3

Or if it’s a really small table, ng-hide/ng-if (based on consolidated element ng-model variable) can be used for this purpose…


#4

here an example of ng-if

In order to make the ng-if to work you need to add a dbr which is hidden (ng-hide=“true”), store the value in a variable ng-model=“product.TotalValue” and then use if in your if ng-if=“product.TotalValue!=‘0’”

          <tr ng-if="product.TotalValue!='0'" ng-repeat="product in page.products">

            <!--  DBR hidden used for the suppress zero -->

              <td ng-hide="true">
                 <tm1-ui-dbr
                   tm1-instance="dev"
                   tm1-cube="Retail"
                   tm1-elements='{{page.title.version}},{{page.title.year}},"All Months","Local",{{page.title.region}},{{product.key}},"Sales Amount"'
                   tm1-data-decimal="0"
                   ng-model="product.TotalValue"
                   >
                </tm1-ui-dbr>
                </td> 

You can find the full code in the attached file: template-data-entry-advanced.html (10.4 KB)


#5

I agree with Stephane, it would be great if this could be made into a standard feature vs. having to code it into every table where you wanted it.


#6

In order to suppress zero in a table you can use ng-if or ng-show. The main difference between these 2 is that ng-if removes rows which do not meet the criteria, on the other hand ng-show only hides the rows. With ng-show, rows which do not meet the criteria will still be in your page but they will be hidden. That is why if you use ng-if, your page will be much faster but be aware that there is a downside with ng-if:

I’ve created the following table:

In this example, I use ng-if, the table creates rows only if the Year value is different to 0 (ng-if="employee.TotalValue!=‘0’).
employee.TotalValue is defined in the first column of the table (ng-model=“employee.TotalValue”):

<tr ng-if="employee.TotalValue!='0'" ng-repeat="employee in page.employees">
		<td>
		{{employee.alias}}
		</td>
		<td class="text-right">
			<tm1-ui-dbr
				tm1-instance="dev"
				tm1-cube="Sales Quota"
				tm1-elements='"Actual",{{page.title.year}},"Year",{{employee.key}},"Amount"'
				tm1-data-decimal="0"
				ng-model="employee.TotalValue"
				>
			</tm1-ui-dbr>
		</td>

The issue now is that if you change the year selection to a year 2011/12 which does not have any data:

and then if you go back to year 2007/08 which should have data, the table will not be displayed:

You will have to refresh the page, in order to see the data.

The workaround for this situation is to use ng-show instead of ng-if:

	<tr ng-show="employee.TotalValue!='0'" ng-repeat="employee in page.employees">

#7

Hi @Vincent thanks for the example and explanation.

Unfortunately from an end user perspective I think the behaviour with ng-if would be perceived as a bug.

  • Table is built with original selection, correct rows are displayed (all good)
  • Selection is changed, depending on data some rows are deleted by ng-if, correct rows display (all good)
  • Selection is changed again back to original selection, some rows are missing (bad)

I think it’s possible for everyone to understand that this behaviour is because ng-if only runs on the rows currently in the table, but to the user it’s still wrong and they don’t get the records that they should. So really the only solution using ng-if would be to make sure the page selections are stored and then have a button to rebuild the page. The problem with this is that the user won’t trust the table and so will probably click this button in addition to changing the selection on each change completely removing any performance advantage.

So really the only way to do it is with ng-show?


#8

There is a simple solution for this, you should have a block that uses ng-repeat/ng-hide to extract the values to use for suppression, i.e. use ng-repeat twice. If you have criteria on an ng-repeat it shouldn’t be based on values that are set inside the ng-repeat.

<div ng-repeat="employee in page.employees" ng-hide="true">
	<tm1-ui-dbr
		tm1-instance="dev"
		tm1-cube="Sales Quota"
		tm1-elements='"Actual",{{page.title.year}},"Year",{{employee.key}},"Amount"'
		tm1-data-decimal="0"
		ng-model="employee.TotalValue"
		>
	</tm1-ui-dbr>
</div>

....

<tr ng-if="employee.TotalValue!='0'" ng-repeat="employee in page.employees">
	<td>
	{{employee.alias}}
	</td>
	<td class="text-right">
		<tm1-ui-dbr
			tm1-instance="dev"
			tm1-cube="Sales Quota"
			tm1-elements='"Actual",{{page.title.year}},"Year",{{employee.key}},"Amount"'
			tm1-data-decimal="0"
			>
		</tm1-ui-dbr>
	</td>
</tr>