ExtJS_FAQ_Grid#Behavior

ExtJS Grid高级用法
本文介绍了ExtJS Grid中的一些高级用法,包括如何在单元格内创建链接、为特定单元格添加点击事件、动态调整列显示及添加操作列等内容,并提供了具体的实现方法和示例代码。

前言,学习ExtJS Grid的新手,官方的这篇FAQ是必读的.

顺手翻译了一小点,大概了解就ok了,挺生硬的,呵呵...

 

翻译自:http://extjs.com/learn/Ext_FAQ_Grid#Behavior

 

5.行为

 

5.1 单元格的链接

 

>方法1: 自定义渲染方法

var yourColumn = {


   header: "Company",


   dataIndex: 'company',


   renderer: function(value, metaData, record, rowIndex, colIndex, store) {


      //在这里面可以按你自己的逻辑组成html然后返回


      return '<a href="http://www.yourURL.com/" target="_blank">'


             + value +'</a>';


   }


}

 

>方法2: 监听Ext.grid.RowSelectionModel的rowselect事件

function handleRowSelect(selectionModel, rowIndex, selectedRecord) {


    //assuming the record has a field named 'url' or build it as you need to


    var url = selectedRecord.get('url');


    //if you want to open another window


    window.open(url);


}


grid.getSelectionModel().on('rowselect', handleRowSelect);

 

5.2 为特殊的单元格添加点击事件

 

>除了下面将介绍的方法外,你还可以考虑下Saki提供的扩展:rowactions和cellactions,在http://www.extjs.eu 可找到

 

>如果你用的是编辑表格,则默认的选择模型是cell selection model,所以你可以监听beforecellselect和cellselect事件.

  它会传递点击的行和列的index。其中行index可以用来找到点击的field。(需要注意,用户有可能会对行进行排序,所以直接用行index来寻找field是不安全的,最好用id来索引)

 

>对Grid的cellclick事件添加一个监听器

当点击的时候,传递row index 和column index 给监听器。其中column index可以用来确定是点击的是哪个field。
(用户有可能会对改变行的位置,如拖拽,所以用column index作为field index是不安全的)

 

cellclick事件的处理函数可以如下代码,找到一些相关的信息:

function(grid, rowIndex, columnIndex, e) {


        // Get the Record for the row


        var record = grid.getStore().getAt(rowIndex);


        // Get field name for the column


        var fieldName = grid.getColumnModel().getDataIndex(columnIndex);


        var data = record.get(fieldName);


    }
 

>一个用cellclick事件切换单元格颜色的例子: http://extjs.com/forum/showthread.php?p=119718#post119718

 

>change the CSS so all cells look like an editor is active, e.g.

.x-grid3-row td.x-grid3-td-<id-of-column> {


	background-color: white;


	padding: 0;


}


.x-grid3-row td.x-grid3-td-<id-of-column> .x-grid3-cell-inner {


	border: 1px solid #a9bfd3;


	padding: 2px 3px 2px 5px;


}
 

5.3 如何添加/删除表格的某几列

   参见http://extjs.com/forum/showthread.php?p=308635#post308635

 

5.4 如何为每行记录都添加一个操作列

 

>方法1:

1)Use the array grid example in your packaged download array-grid.js

以自带例子里面的array-grid.js来示范

 

2)Add an extra column to the column model definition and a custom rendere

添加额外的一列

{header: "Controls", 
width: 60, 
sortable: false, 
renderer: function() {
    return '<div class="controlBtn">
            <img src="../shared/icons/fam/cog_edit.png"
            width="16" height="16" 
            class="control_edit">
            <img src="../shared/icons/fam/folder_go.png"
            width="16" height="16"
            class="control_go"></div>';
}, 
dataIndex: 'company'}

 

3)Then you would setup an event handler on the click event.

添加事件处理函数

grid.on('click', function(e) {
        var btn = e.getTarget('.controlBtn');        
        if (btn) {
            var t = e.getTarget();
            var v = this.getView();
            var rowIdx = v.findRowIndex(t);
            var record = this.getStore().getAt(rowIdx);            
            var control = t.className.split('_')[1];
            switch (control) {
                case 'edit':
                    console.log('edit this record - ' + record.id);
                    break;
                case 'go':
                    console.log('go to this record - ' + record.id);
                    break;
            }            
        }
    }, grid);
 

4)Add the following CSS rule in array-grid.html to give some padding and change the cursor.

<style>
   .controlBtn img {
      padding-left: 4px;
      cursor: pointer;
   }
</style>
 

 

5)Using this same method you could add as many tools as you would like in the controls section and always give them the css class "controls_{toolname}". Ideally you would break this out into an XTemplate so that you could simply pass in whatever tools you would like to use and output them on the grid as well.

 

 

>方法2:

使用RowAction这个扩展 http://extjs.com/forum/showthread.php?t=24508

 

 

 

 

 

 

 

 

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值