GWT-在celltable列checkboxcell中选择我想要的所有记录选择显示记录

时间:2015-06-23 09:36:42

标签: gwt

Frineds,

我正在使用celltable,他们是一个列,我在表头中选择所有记录选项,我也使用在一页显示最多15条记录的寻呼机。当我点击selectall选项时,它将选择所有当前页面为2,3,4的记录,....简而言之,所有记录都被选中(如果总记录为100,则选择100条记录)。所以我只想选择显示页面记录不是全部...... 参考代码是 -

      final SelectionModel < GenericFirewallRule > selectionModel = 
new MultiSelectionModel < GenericFirewallRule > ();
            deleteRuleCellTable.setSelectionModel(selectionModel,DefaultSelectionEventManager. < GenericFirewallRule > createCheckboxManager());
    //      CheckboxCell cbForHeader = new CheckboxCell();

    Column < GenericFirewallRule, Boolean > checkColumn = new Column < GenericFirewallRule, Boolean > (
    new CheckboxCell()) {@Override
        public Boolean getValue(GenericFirewallRule object) {

            if(object == null || object.getRuleNumber() == null){
                   return null;
            }else{
            if (selectionModel.isSelected(object)) {
                if (!ruleListForDelete.contains(object)) {
                    ruleListForDelete.add(object);
                }
            } else {
                if (ruleListForDelete.contains(object)) {
                    ruleListForDelete.remove(object);
                }
            }

            System.out.println("ruleListForDelete : " + ruleListForDelete);
            return selectionModel.isSelected(object);
            }
        }
    };

请建议我解决方案......

1 个答案:

答案 0 :(得分:0)

您可以这样做:

selectAllHeader = new Header<Boolean>(new HeaderCheckbox()) {

    @Override
    public Boolean getValue() {
        for (T item : getVisibleItems()) {
            if (!getSelectionModel().isSelected(item)) {
                return false;
            }
        }
        return getVisibleItems().size() > 0;
    }
};

selectAllHeader.setUpdater(new ValueUpdater<Boolean>() {

    @Override
    public void update(Boolean value) {
        for (T object : getVisibleItems()) {
            getSelectionModel().setSelected(object, value);
        }
    }

});

public class HeaderCheckbox extends CheckboxCell {

    private final SafeHtml INPUT_CHECKED = SafeHtmlUtils.fromSafeConstant("<input type=\"checkbox\" tabindex=\"-1\" checked/>");
    private final SafeHtml INPUT_UNCHECKED = SafeHtmlUtils.fromSafeConstant("<input type=\"checkbox\" tabindex=\"-1\"/>");

    public HeaderCheckbox() {
    }

    @Override
    public void render(Context context, Boolean value, SafeHtmlBuilder sb) {
      if (value != null && value) {
        sb.append(INPUT_CHECKED);
      } else {
        sb.append(INPUT_UNCHECKED);
      }
    }
}