Extjs grid显示bool型值,添加双击事件

有的时候,数据库里面存储的bool型是1, 0或者Y, N等表示。但是在前台界面中希望用跟友好的形式进行显示。这就需要一个转换,将数据库中的值转换为想要显示的。

方法1:后台处理。读取将要显示的列表(通常是分页显示,数据量也不会太大),循环进行处理。

List alist = service.getList(fieldMap, pageModel, orderModel);

if(alist != null) {

for(int i = 0; i < alist.size(); i++){

if(alist.get(i).getObj().getBool()!=null && alist.get(i).getObj().getBool().equals(1)) {

alist.get(i).getObj().setBool(“是”)

}else {

alist.get(i).getObj().setBool(“否”)

}

}

}

方法2:前台处理,利用Extjs直接处理:

renderer: function(value) {
   if (value == "0") {
      return "否";
   } else if (value == "1") {
      return "是";
   } else {
      return null;
   }
}
==============
grid的双击事件:
listeners: {
		    itemdblclick: function(dataview, index, item, e){
		        var rows = sendboxPanel.getSelectionModel().getSelection();
		    }
		}
参考:1. http://stackoverflow.com/questions/5751616/how-to-add
-row-double-click-event-listener-when-extending-grid-panel-with-ext-de
2. http://stackoverflow.com/questions/4389410/how-to-get
-the-data-from-a-row-that-was-double-clicked-in-an-extjs-grid
This entry was posted in Computer, Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s