首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

EXTJS grid 排序 小弟我给显示的字段设置了 SORTABLE=TRUE 为什么有的字段可以排序有的字段不可以排序呢

2012-02-10 
EXTJS grid 排序 我给显示的字段设置了 SORTABLETRUE 为什么有的字段可以排序有的字段不可以排序呢scrip

EXTJS grid 排序 我给显示的字段设置了 SORTABLE=TRUE 为什么有的字段可以排序有的字段不可以排序呢
<script type="text/javascript">
  var IDS=new Array();
  Ext.onReady(function(){
  var roleCombox;
  var bbar;
  Ext.BLANK_IMAGE_URL = "<%=basePath%>js/extjs/resources/images/default/s.gif";
  Ext.QuickTips.init();
  Ext.lib.Ajax.defaultPostHeader+=";charset=utf-8";
  var cm=new Ext.grid.ColumnModel([
 {header:'角色名称',dateIndex:'ROLE_NAME',sortable:true},
{header:'创建人',dataIndex:'CREATE_USER_NAME',sortable:true},
{header:'创建时间',dataIndex:'CREATE_TIME',sortable:true}
 ]);
 //数据源的获取
 var store = new Ext.data.Store({
  reader: new Ext.data.JsonReader({
  totalProperty: "results",
  root: "items",
  id: "store"
  },
  Ext.data.Record.create(['ROLE_NAME','CREATE_USER_NAME','CREATE_TIME','ROLE_ID'])
 ),
  proxy : new Ext.data.HttpProxy({
  url : '<%=basePath%>system/role_findRole.action'
  });
  store.load({params:{start:0, limit:25}});
  var tbar=new Ext.Toolbar({
  name:'usertbar',
  id:'usertbar'
  });
  tbar.render('toolbar');
  varcomboxRoleStore=new Ext.data.JsonStore({
  url:'<%=basePath%>system/role_findRoleByCom.action',
  root:'items',
  totalProperty: 'results',
  fields:[
  {name:'ROLE_ID', mapping:'ROLE_ID'},
  {name:'ROLE_NAME', mapping:'ROLE_NAME'}
  ],
  disableCaching:false,
  autoLoad:true
  });
  roleCombox=new Ext.form.ComboBox({
  xtype : 'combo',
  name:'ROLE_ID',
  id:'ROLE_ID',
  store: comboxRoleStore,
  displayField:'ROLE_NAME',
  valueField:'ROLE_NAME',
  emptyText:'请输入查询',
  width:160,
  listWidth:200,
  minHeight:100,
  editable:true,
  allowBlank:true,
  mode:'local', 
  typeAhead: false,
  loadingText:'loading...',
  hiddenName:'ROLE_NAME',
  triggerAction:'all',
   
  onKeyUp : function(e){
  var a=e.getKey();
  if(e.getKey()==e.SPACE||(parseInt(a)>48&&parseInt(a)<58)){
  this.store.baseParams = { query:this.getEl().dom.value };
  this.collapse();
  this.store.reload();
  }
  }
  });
  comboxRoleStore.load({params:{query:roleCombox.getRawValue(),start:0,limit:10}});
   
  var searchBus=new Ext.Toolbar.Button({text:'查询',handler:searchRole,cls:'x-btn-text-icon',icon: 'images/ico/sousuo.gif'});
  var roleCreate=new Ext.Toolbar.Button({text:'新增',handler:create,cls:'x-btn-text-icon',icon: 'images/ico/tianjia.gif'});
  var roleDelete=new Ext.Toolbar.Button({text:'删除',handler:deleteRole,cls:'x-btn-text-icon',icon: 'images/ico/shanchu.gif'});
  var roleModify=new Ext.Toolbar.Button({text:'修改',handler:modify,cls:'x-btn-text-icon',icon: 'images/ico/xiugai.gif'});
  var roleMenu=new Ext.Toolbar.Button({text:'角色配置菜单',handler:addRoleMenu,cls:'x-btn-text-icon',icon: 'images/ico/shezhi.gif'});
  var rolefun=new Ext.Toolbar.Button({text:'角色功能权限',handler:findmenurole,cls:'x-btn-text-icon',icon: 'images/ico/shenzhi.gif'});


  tbar.add(roleCombox);
  tbar.add(searchBus);
  tbar.add({xtype:'tbseparator'});
  tbar.add(roleCreate);
  tbar.add({xtype:'tbseparator'});
  tbar.add(roleDelete);
  tbar.add({xtype:'tbseparator'});
  tbar.add(roleModify);
  tbar.add({xtype:'tbseparator'});
  tbar.add(roleMenu);
  tbar.add({xtype:'tbseparator'});
  tbar.add(rolefun);
  bbar=new Ext.PagingToolbar({
 pageSize:25,
 store:store,
 displayInfo:true,
 displayMsg:'显示第{0}条到{1}条记录, 一共{2}条',
 emptyMsg:"没有记录"
 });
  var grid=new Ext.grid.GridPanel({
 renderTo:'grid',
 store:store,
 cm:cm,
 width: Ext.get("grid").getWidth(), 
  height: Ext.get("grid").getHeight(),
  viewConfig:{
  forceFit:true
  },
 bbar:bbar
 });
  function searchRole(){
   
  var values =roleCombox.getEl().getValue();
 
  grid.store.proxy =new Ext.data.HttpProxy({url:'<%=basePath%>system/role_findRole.action?ROLE_NAME=' + values,method : 'POST'});
  grid.store.reload({params:{start:0, limit:25}});
  }
 
  function deleteRole(){
 var record = grid.getSelectionModel().getSelected();
if(!record){
top.Ext.Msg.alert("信息", "请选择要删除的一项");
}else{
top.Ext.MessageBox.confirm("请确认","是否真的要删除指定的内容",function(button,text){ 
  if(button=='yes'){
  var rid =record.get('ROLE_ID');
 
roleService.deleteRole(rid,function (data){
if(data==true){
top.Ext.Msg.alert('信息','删除成功');
var s=bbar.cursor;
store.load({params:{start:s, limit:25}});
}else{
top.Ext.Msg.alert('信息','删除失败');
}
});
}
});
}
 }
 var cuswin=null;
 var cuspanle=null;
function createwin(){
cuswin = new top.Ext.Window({
 title:'角色新增',
 width:550,
 height:425,
 plain:true,
 closable:true,
 resizable:true,
 closeAction:'close',
 id:'cuswin',
 modal:true,
 listeners : {'hide':{fn: makesure}}
 });
cuspanle = new top.Ext.FormPanel({
  labelAlign : 'right',
  border:false,
  buttonAlign : 'center',
  frame : true,
  width:550,
  id:'cusfrm',
  layout : "form", 
  labelWidth :75,
  defaultType : 'textfield',
  items : [{
 xtype : 'tabpanel',
  plain : true,
  activeTab : 0,
  height : 340,
  defaults : { bodyStyle : 'padding:10px'},
  items : [{
  title : '基本信息',
  items:[{
  xtype:'fieldset',
  title:'基本信息',
items:[{
layout:'form',
items:[{xtype : "textfield",
  fieldLabel : '角色名称',
  name : 'ROLE_NAME',


  width:390,
  id :'ROLE_NAME'}]
}]}]}] }],
  buttons:[{text:'保存',handler:submit},{text:'取消',handler:submit}]
});}
 
 
 



ROLE_NAME不可以排序 其他 两个字段都可以点击排序 我都设置了 sortable:true

[解决办法]
中文排序不能用true,


 Ext.data.Store.prototype.applySort = function(){ //重载 applySort
 
if(this.sortInfo && !this.remoteSort){
 
var s = this.sortInfo, f = s.field;
 
var st = this.fields.get(f).sortType;
 
var fn = function(r1, r2){
 
var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
 
// 添加:修复汉字排序异常的Bug
 
if(typeof(v1) == "string"){ //若为字符串,
 
return v1.localeCompare(v2);//则用 localeCompare 比较汉字字符串, Firefox 与 IE 均支持
 
}
 
// 添加结束
 
return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
 
};
 
this.data.sort(s.direction, fn);
 
if(this.snapshot && this.snapshot != this.data){
 
this.snapshot.sort(s.direction, fn);
 
}
 
}
 
}; 


热点排行
Bad Request.