前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ExtJs学习笔记(7)_获取GridPanel选中行的详细信息

ExtJs学习笔记(7)_获取GridPanel选中行的详细信息

作者头像
菩提树下的杨过
发布2018-01-22 17:33:01
1.1K0
发布2018-01-22 17:33:01
举报

这一节,我们将学习如何获取Grid当前选中行的信息

1.xml数据源内容:

代码语言:js
复制
<?xml version="1.0" encoding="UTF-8"?>
 <Data>
 <Items> 
 <TotalResults>203</TotalResults>
 <TotalPages>21</TotalPages>
 <Item>
 <ASIN>0446355453</ASIN> 
 <Author>Jimmy.Yang</Author>
 <Manufacturer>Warner Books</Manufacturer>
 <ProductGroup>Book</ProductGroup>
 <Title>Master of the Game</Title> 
 </Item>
 <Item>
 <ASIN>0446613657</ASIN> 
 <Author>Sidney Sheldon</Author>
 <Manufacturer>Warner Books</Manufacturer>
 <ProductGroup>Book</ProductGroup>
 <Title>Are You Afraid of the Dark?</Title> 
 </Item> 
 </Items>
 </Data>

2.静态页内容:

代码语言:js
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <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> 
 <style type="text/css">
         *{font-size:12px;line-height:130%;}
 </style>
 <title>ExtJs_Grid_Xml</title>
 </head>
 <body>
 
 <script type="text/javascript">
 
     Ext.onReady(function() {
 
 var store = new Ext.data.Store({
             url: 'GridData.xml',
             reader: new Ext.data.XmlReader(
                 { record: 'Item' },
                 ["ASIN", "Author", "Manufacturer", "ProductGroup", "Title"])
         });
 
 function SeeDetail(ID) {
 return '<a href="Book.aspx?id=' + ID + '" target="_blank">' + ID + '</span>';
         }
 
 var grid = new Ext.grid.GridPanel({
             store: store,
             frame: true,
             columns: [
                 { id: "ASIN", header: "出版号", width: 120, renderer: SeeDetail, dataIndex: 'ASIN', sortable: true },
                 { header: "作者", width: 120, dataIndex: 'Author', sortable: true },
                 { header: "书名", width: 180, dataIndex: 'Title', sortable: true },
                 { header: "制作商", width: 115, dataIndex: 'Manufacturer', sortable: false },
                 { header: "产品组", width: 100, dataIndex: 'ProductGroup', sortable: false}],
             renderTo: 'example-grid',
             viewConfig: { columnsText: '显示列', sortAscText: '升序', sortDescText: '降序' },
             width: 660,
             height: 100,
             sm: new Ext.grid.RowSelectionModel({ singleSelect: true })
         });    
 
 
 // 定义详细信息的显示模板
  var bookTplMarkup = [
 '出版号: <a href="http://www.baidu.com/{ASIN}" target="_blank">{ASIN}</a><br/>',
 '作者: {Author}<br/>',
 '书名: {Title}<br/>',
 '产品组: {ProductGroup}<br/>'
         ];
 
 var bookTpl = new Ext.Template(bookTplMarkup); //ExtJs的模板组件
 
 var p = new Ext.Panel({
             id: "detailPanel",
             title: '详细情况', //标题
             collapsible: true, //右上角上的那个收缩按钮,设为false则不显示
             renderTo: 'example-grid', //这个panel显示在html中id为container的层中
             width: 660,
             height: 100,
             html: "请在上面网格中选择一行数据"//panel主体中的内容,可以执行html代码
         });
 
         grid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) {
 var detailPanel = Ext.getCmp('detailPanel');
             bookTpl.overwrite(detailPanel.body, r.data);
             Ext.MessageBox.alert("提示","您选择的出版号是:" + r.data.ASIN);
         });
         store.load();
     });
 
 </script>
 
 <div id="example-grid" style="margin:10px 0 0 10px"></div>
 </body>
 </html>
 

效果图

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2008-08-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档