禁用Extjs中propertyGrid的自动排序

本文介绍了如何在ExtJS中避免直接修改源代码来禁用propertyGrid的自动排序功能,而是通过添加配置属性实现灵活控制。

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

书上讲的解决办法是直接修改Extjs中的ext-all.js文件,注释掉里面的b.store.sort("name", "ASC");这句代码。

这样虽然能达到效果,但是如果有的propertyGrid需要这种自动排序的功能,岂不是不行!

既然要修改源代码,那么就不要修改得这样死,废话不说了,开始吧!

我们可以在propertyGrid上增加一个配置属性,标识是否需要自动排序,比如就叫autoSort,初始值设置为true,在我们new propertyGrid的时候,如果不想自动排序,那么就配置autoSort的值为false,这样就能达到我们想要的效果了!

具体的代码如下:

Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {autoSort:true,enableColumnMove:false,stripeRows:false,trackMouseOver:false,clicksToEdit:1,enableHdMenu:false,viewConfig:{forceFit:true},initComponent:function() {
this.customEditors = this.customEditors || {};
this.lastEditRow = null;
var b = new Ext.grid.PropertyStore(this);
this.propStore = b;
var a = new Ext.grid.PropertyColumnModel(this, b);
this.addEvents("beforepropertychange", "propertychange");
this.cm = a;
this.ds = b.store;
if (this.autoSort) {
b.store.sort("name", "ASC");
}
Ext.grid.PropertyGrid.superclass.initComponent.call(this);

……

使用时:
var processPropertyGrid = new Ext.grid.PropertyGrid({
id:'process-PropertyGrid',
title:'工序属性表',
closable:false,
height:400,
autoScroll:true,
autoSort:false
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值