gwt - 单元格表 - 添加额外的行 [英] gwt - celltable - adding extra row

查看:24
本文介绍了gwt - 单元格表 - 添加额外的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处输入代码我有一个单元格表,其中的列包含一些数字.我想在表的末尾添加一个额外的行,用于保存每列的总数.有没有办法做到这一点?

enter code hereI have a celltable and the columns contains some numbers. I want to add an extra row at the end of the table which will hold the total for each column. Is there any way to do this?

以下是我的代码:

   import java.util.*;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.ListDataProvider;

public class TestProject implements EntryPoint 
{

 private static int totalSalary=0;
 private static class Contact 
 {
        private final String salary;
        private final String name;

        public Contact(String name, String salary) 
        {
          this.name = name;
          this.salary = salary;
        }
 }

private static List<Contact> CONTACTS = Arrays.asList(new Contact("John","100000"), 
                                                      new Contact("Mary", "200000"), 
                                                      new Contact("Zander", "300000"));
/**
 * This is the entry point method.
 */
public void onModuleLoad() 
{
    final CellTable<Contact> table = new CellTable<Contact>();

    // Create name column.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() 
    {
      @Override
      public String getValue(Contact contact) 
      {
        return contact.name;
      }
    };

    // Create address column.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() 
    {
      @Override
      public String getValue(Contact contact) 
      {
        totalSalary+=Integer.parseInt(contact.salary);
        return contact.salary;
      }
    };

    // Add the columns.
    table.addColumn(nameColumn, "Name");
    table.addColumn(addressColumn, "Salary");

    // Create a data provider.
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

    // Add the data to the data provider, which automatically pushes it to the
    // widget.
    final List<Contact> list = dataProvider.getList();
    for (Contact contact : CONTACTS) {
      list.add(contact);
    }

    // We know that the data is sorted alphabetically by default.
    table.getColumnSortList().push(nameColumn);

    Contact total = new Contact("Total: ",totalSalary+"");
    list.add(total);



    // Add it to the root panel.
    RootPanel.get().add(table);
    //RootPanel.get().add(add);
}

}

推荐答案

此外,我建议您在添加列时使用 footer-Argument:addColumn(Column col, Header header)

Also I would suggest that you use the footer-Argument when you add the column: addColumn(Column col, Header header)

这篇关于gwt - 单元格表 - 添加额外的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆