<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>03.grid</title> <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" /> <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script> <script type="text/javascript" src="../../ext-all.js"></script> <script type="text/javascript"> Ext.onReady(function(){ var cm = new Ext.grid.ColumnModel([ {header:'编号',dataIndex:'id'}, {header:'名称',dataIndex:'name'}, {header:'描述',dataIndex:'descn'} ]); var data = [ ['1','name1','descn1'], ['2','name2','descn2'], ['3','name3','descn3'], ['4','name4','descn4'], ['5','name5','descn5'] ]; var store = new Ext.data.Store({ proxy: new Ext.data.MemoryProxy(data), reader: new Ext.data.ArrayReader({}, [ {name: 'id'}, {name: 'name'}, {name: 'descn'} ]) }); store.load(); var getRowIndex = new Ext.grid.RowSelectionModel({ listeners: { rowselect: function(sm, row, rec) { alert(row+1); //计算机计算是从0开始算第一行的,所以加1 补充一下 // store.indexOf(rec); //这个是取该选中的rec在store中的位置,应该就是行号 } } }); // 另一种方法 /* grid.getSelectionModel().on('rowselect',function(sm,rowIndx,r){ }) */ var grid = new Ext.grid.GridPanel({ autoHeight: true, renderTo: 'grid', store: store, cm: cm, sm:getRowIndex }); }); </script> </head> <body> <script type="text/javascript" src="../shared/examples.js"></script> <div id="grid"></div> </body> </html>