gwtgwt-celltable

How to Update Cell Table Footer Dynamically


I am trying to add footer to the celltable and finding hard time to change the celltable footer dynamically but i am able to add while creating columns like below

cellTable.addColumn(qty, "Qty",Integer.toString(totalQty)); 

This is not i am looking for,Is there any way to set footer to cell table dynamically.Any help?


Solution

  • You need to implement a custom Header and add it to the column which should contain that footer. For example:

    public class QuantityFooter extends Header<Number> {
    
        private final Number totalQty;
    
        public QuantityFooter(Number totalQty) {
            super(new NumberCell());
            this.totalQty = totalQty;
        }
    
        public void setQuantity(Number totalQty) {
            this.totalQty = totalQty;
        }
    
        @Override
        public Number getValue() {
            return totalQty;
        }
    }
    

    Then add it to the column:

    QuantityFooter quantityFooter = new QuantityFooter(0);
    cellTable.addColumn(qty, new TextHeader("Qty"),quantityFooter ); 
    

    When you need to update the footer you just call quantityFooter.setQuantity(10) and you probably need to redraw the headers/footers with redrawHeader() and redrawFooters()