Mohemmed Bilal Ilyas
Mohemmed Bilal Ilyas

Reputation: 31

Perform multiplication in zk grid

How I can perform multiplication in zk grid my grid is look like this

Rate Qty Amount

|2 ----- 3 ---6 |
|4------4----16|

Upvotes: 0

Views: 94

Answers (1)

chillworld
chillworld

Reputation: 4277

The each stands for the var name how you did name the variable in the for each. By default this is each. If MVVM :

you could add to your VM :

public long countNumbers (int first, int second) {
    return (long)first + second;
}

in zul :

<label value="@load(vm.countNumbers(each.number1, each.numer2))"/>

In MVVM or MVC :

If its needed regulary, you could write your own taglib with this method.(works also for MVC)
You need to create a tld file in the WEB-INF/tld folder. :

<taglib>
    <!-- count numbers to each other -->
    <function>
        <name>countUp</name>
        <function-class>your.path.Classname</function-class>
        <function-signature>
            java.lang.Long countNumbers(java.lang.Integer, java.lang.Integer)
        </function-signature>
        <description>counts the 2 numbers to each other.</description>
    </function>
</taglib>

Then you create a new java util class (watch out, the method need to be static):

public static Long countNumbers (Integer first, Integer second) {
    return (Long)first + second;
}

And in zul :

<?taglib uri="/WEB-INF/tld/taglibname.tld" prefix="ct"?>

<label  value="@load(ct:countUp(each.number1,each.number2))"/>

If you use a renderer, you set all the objects of a row directly in java so counting up 2 values there should not be a problem, cause you will have the original object already.

Edit : change the return type to long (2 big int can cause overflow)

Upvotes: 1

Related Questions