读书人

ext 漫笔

发布时间: 2012-11-22 00:16:41 作者: rapoo

ext 随笔
******************************************************************************************************************
要实现从文本框中录入数据,作为查询条件,查询出combox的下拉
var text,combo;
初始化过程自己写
text.on('change',function(){
combo.store.baseParams={text:text.getValue()};
combo.reload();
});
=================================================================================================
grid自动显示行号
var cm=new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(), //行号
{header:'编号',dataIndex:'id'},
{header:'性别',dataIndex:'sex'},
......
]);

运用,在HTML里添加一个按钮 id为:“remove”,触发删除grid第2行数据
Ext.get('remove').on('click',function(){
sotre.remove(store.getAt(1));
grid.view.refresh(); //不可丢,否则行号变得不连续
});
==========================================================================================================
复选框
var sm=new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(), //行号
sm,
{header:'编号',dataIndex:'id'},
{header:'性别',dataIndex:'sex'},
......
]);
var grid=new Ext.grid.GridPanel({
renderTo:'grid',
store:store,
cm:cm,
sm:sm
});

sm身兼两职,即要放入cm中,又要放到Grid中,实用中取消原始的选择功能,只允许用户通过复选框执行选中操作,
var sm=new Ext.grid.CheckboxSelectionModel({handleMouseDown:Ext.emptyFn});
=============================================================================================
只允许单选一行
var grid=new Ext.grid.GridPanel({
renderTo:'grid',
store:store,
cm:cm,
sm:new Ext.grid.RowSelectionModel({singleSelect:true});
});
======================================================================================================
单元格选择模型
在EditorGrid默认使用CellSelectionModel当然特可以设为RowSelectionModel({singleSelect:true});
单击某一行弹出一个对话框,并且显示当前的一些消息
grid.on('click',function(){
var selections=grid.getSelectionModel().getSelections();
for(var i=0;i<selections.length;i++){
var record=selections[i];
Ext.Msg.alert('提示',record.get("id")+","+record.get("name")...);

}

});
================================================================================================================
Ext.grid.GridPanel设置的各种监听器可看做COntroller控制器,其默认就为view视图,无须自己创建GridView实例,希望操作GridView属性时,通过getView()获取当前表格使用的视图实例
Ext.get('scroll').on('click',function(){
grid.getView().scrollToTop(); //显示滑动条位置;;
});
Ext.get('focus').on('click',function(){
grid.getView().focusCell(0,0); //设置焦点;
var cell=grid.getView().getCell(0,0);
cell.style.backgroundColor='red';
});

===================================================================================

读书人网 >Web前端

热点推荐