extremetable 的两个特性扩展

本文介绍了Extremecomponents组件中的Extremetable两个实用扩展特性:直接跳转到指定页码及checkbox列扩展。通过自定义工具栏和单元格实现增强功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

extremetable 的两个特性扩展

好久没有上自己的blog了,前段时间一直在为跳槽的事做思想斗争,本来已经与上海的那家公司谈妥了决定过去,但是考虑到一些客观问题最终还是放弃了这个决定,之后到现在的这一段时间一直在为大唐湖南分公司的一个项目忙得焦头烂额,但最终还是把一些前期要处理的问题定下来了,所以现在有时间坐下来为自己的blog添加一些内容。

在信息管理系统中会用到大量的List列表,网络有许多非常好用的标签,我们项目中用到的是extremecomponents组件,这是个封装性和扩展性非常强大的组件,网络中也有一些关于该组件的讨论组,遗憾的是对一些应用需求的满足还不太充足,相应的资料也不太多,我就我对两个特性的扩展方法拿出来跟大家一起交流:

1)直接跳转到指定页码特性的扩展

public class CustomToolbar extends DefaultToolbar {

 public CustomToolbar(HtmlBuilder html, TableModel model) {

  super(html, model);

 }

 protected void columnRight(HtmlBuilder html, TableModel model) {

  // CustomToolbarBuilder customToolbarBuilder = new

  // CustomToolbarBuilder(html, model);

  //

  // customToolbarBuilder.pagesDisplayedDroplist();

  boolean showPagination = BuilderUtils.showPagination(model);

  boolean showExports = BuilderUtils.showExports(model);

  CustomToolbarBuilder toolbarBuilder = new CustomToolbarBuilder(html,

    model);

  html.td(2).align("right").close();

  html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(

    BuilderConstants.TOOLBAR_CSS).close();

  html.tr(3).close();

  if (showPagination) {

   html.td(4).close();

   toolbarBuilder.firstPageItemAsImage();

   html.tdEnd();

   html.td(4).close();

   toolbarBuilder.prevPageItemAsImage();

   html.tdEnd();

   html.td(4).close();

   toolbarBuilder.nextPageItemAsImage();

   html.tdEnd();

   html.td(4).close();

   toolbarBuilder.lastPageItemAsImage();

   html.tdEnd();

   html.td(4).close();

   toolbarBuilder.separator();

   html.tdEnd();

   html.td(4).style("width:20px").close();

   html.newline();

   html.tabs(4);

   toolbarBuilder.pagesDisplayedDroplist();

   html.img();

   html.src(BuilderUtils.getImage(model, "pageDisplayed"));

   html.style("border:0");

   html.alt("当前页码");

   html.xclose();

   html.tdEnd();

   html.td(4).close();

   toolbarBuilder.separator();

   html.tdEnd();

   html.td(4).style("width:20px").close();

   html.newline();

   html.tabs(4);

   toolbarBuilder.rowsDisplayedDroplist();

   html.img();

   html.src(BuilderUtils.getImage(model,

     BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));

   html.style("border:0");

   html.alt("每页记录数");

   html.xclose();

   html.tdEnd();

   if (showExports) {

    html.td(4).close();

    toolbarBuilder.separator();

    html.tdEnd();

   }

  }

  if (showExports) {

   Iterator iterator = model.getExportHandler().getExports()

     .iterator();

   for (Iterator iter = iterator; iter.hasNext();) {

    html.td(4).close();

    Export export = (Export) iter.next();

    toolbarBuilder.exportItemAsImage(export);

    html.tdEnd();

   }

  }

  html.trEnd(3);

  html.tableEnd(2);

  html.newline();

  html.tabs(2);

  html.tdEnd();

 }

}

public class CustomToolbarBuilder extends ToolbarBuilder {

 public CustomToolbarBuilder(HtmlBuilder html, TableModel model) {

  super(html, model);

 }

 public void pagesDisplayedDroplist() {

  HtmlBuilder html = getHtmlBuilder();

  TableModel model = getTableModel();

  int totalPages = BuilderUtils.getTotalPages(model);

  int currentPage = model.getLimit().getPage();

  StringBuffer onchange = new StringBuffer();

  onchange.append(new CustomTableActions(model).getPageAction());

  html.select().name("pages");

  html.onchange(onchange.toString());

  html.close();

  html.newline();

  html.tabs(4);

  for (int i = 1; i <= totalPages; i++) {

   html.option().value(String.valueOf(i));

   if (currentPage == i) {

    html.selected();

   }

   html.close();

   html.append(String.valueOf(i));

   html.optionEnd();

  }

  html.newline();

  html.tabs(4);

  html.selectEnd();

 }

}

public class CustomToolbarView extends HtmlView {

 protected void toolbar(HtmlBuilder html, TableModel model) {

  new CustomToolbar(html, model).layout();

 }

}

public class CustomTableActions extends TableActions {

 public CustomTableActions(TableModel model) {

  super(model);

 }

 public String getPageAction() {

  TableModel model = getTableModel();

  StringBuffer action = new StringBuffer("javascript:");

  action.append(getClearedExportTableIdParameters());

  String form = BuilderUtils.getForm(model);

  action.append("document.forms.").append(form).append(".");

  action.append(model.getTableHandler().prefixWithTableId()).append(

    TableConstants.PAGE);

  String page = "this.options[this.selectedIndex].value";

  action.append(".value=").append(page).append(";");

  action.append(getOnInvokeAction());

  return action.toString();

 }

}

2)checkbox列的扩展

public class CustomCheckboxCell implements Cell {

 public String getExportDisplay(TableModel model, Column column) {

  return null;

 }

 public String getHtmlDisplay(TableModel model, Column column) {

  ColumnBuilder columnBuilder = new ColumnBuilder(column);

  columnBuilder.tdStart();

  try {

   String cid = column.getProperty();

   if (cid == null) {

    cid = column.getAlias();

   }

   HtmlBuilder html = columnBuilder.getHtmlBuilder();

   html.input(column.getAlias()).name(cid).value(

     String.valueOf(column.getValue()));

   html.onclick("CheckboxClick(this)");

   html.xclose();

  } catch (Exception e) {

  }

  columnBuilder.tdEnd();

  return columnBuilder.toString();

 }

}

public class CustomSelectallHeaderCell extends HeaderCell {

 protected void buildHeaderHtml(HtmlBuilder html, TableModel model,

   Column column, String headerClass, String sortImage,

   String sortOrder) {

  html.td(2);

  if (StringUtils.isNotEmpty(headerClass)) {

   html.styleClass(headerClass);

  }

  if (StringUtils.isNotEmpty(column.getHeaderStyle())) {

   html.style(column.getHeaderStyle());

  }

  if (StringUtils.isNotEmpty(column.getWidth())) {

   html.width(column.getWidth());

  }

  html.onclick("selectall()");

  html.onmouseover("this.className='"

    + BuilderConstants.TABLE_HEADER_SORT_CSS

    + "';this.style.cursor='pointer'");

  if (StringUtils.isNotEmpty(headerClass)) {

   html.onmouseout("this.className='" + headerClass

     + "';this.style.cursor='default'");

  } else {

   html.onmouseout("this.className='"

     + BuilderConstants.TABLE_HEADER_CSS

     + "';this.style.cursor='default'");

  }

  html.close();

  html.append(column.getTitle());

  html.tdEnd();

 }

最后的效果如下:

 

 

源文档 <http://cache.baidu.com/c?word=column%3B%2E%3Bgetproperty&url=http%3A//blog%2Ecsdn%2Enet/vknight/archive/2006/08/10/1048209%2Easpx&b=24&a=16&user=baidu>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值