extjs grid 的渲染和选择某一列的数据实例

来源:互联网 发布:java 训练 编辑:程序博客网 时间:2024/05/17 03:55

<!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" />
<title>栏目增加</title>
<link rel="stylesheet" type="text/css" href="../js/resources/css/ext-all.css"/>

    <!-- GC -->
    <!-- LIBS -->
    <script type="text/javascript" src="../js/adapter/ext/ext-base.js"></script>

    <!-- ENDLIBS -->

    <script type="text/javascript" src="../js/ext-all.js"></script>

 <script type="text/javascript">
 Ext.MyViewport=Ext.extend(Ext.Viewport ,{
xtype:"viewport",
 initComponent: function(){
  this.items=[
   {
    xtype:"grid",
    title:"留言管理表格",
    height:300,
    store: store,
    id:'biao',
    sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
    loadMask:true,//表现Loading动
    columns:[
     {
      header:"id",
      sortable:true,
      resizable:true,
      dataIndex:"id",
      align:'center',
      width:100
     },
     {
      header:"title",
      sortable:true,
      resizable:true,
      dataIndex:"title",
      align:'center',
      width:100
     },
     {
      header:"message",
      sortable:true,
      resizable:true,
      dataIndex:"message",
      align:'center',
      width:100
     },
     {
      header:"up",
      sortable:true,
      resizable:true,
      dataIndex:"up",
      align:'center',
      width:100,
      renderer:function(value){
       if(value=='up')
       {
        return "<span><img src='../img/bian.gif' id='geng' onclick='up()'></span>";
       }
      }
     },
     {
      header:"shan",
      sortable:true,
      resizable:true,
      dataIndex:"shan",
      align:'center',
      width:100,
      renderer:function(value){
       if(value=='shan')
       {
        return "<span><img src='../img/shan.gif'></span>";
       }
      }
     }
    ],
     bbar: new Ext.PagingToolbar({
       pageSize: 5, // data to display
       store: store,
       displayInfo: true,
       displayMsg: 'Displaying topics {0} - {1} of {2}',
       emptyMsg: "No topics to display"  
      })

   }
  ]
  Ext.MyViewport.superclass.initComponent.call(this);
 }
})
var store = new Ext.data.JsonStore({
    totalProperty: 'total', // total data, see json output
    root: 'root', // see json output
    url: '../extjs_json.php',   
        fields: [
            {name: 'id'},
           {name: 'title', type: 'string'},
           {name: 'message', type: 'string'},
     {name: 'up', type: 'string'},
     {name: 'shan', type: 'string'}
        ]
    });
 store.load({params:{start: 0, limit: 5}});    
  Ext.onReady(function(){
   new Ext.MyViewport();
  });
  function up()
  {
   Ext.onReady(function(){
   var selModel=Ext.getCmp('biao').getSelectionModel();
   var record=selModel.getSelected();
   Ext.Msg.alert('',record.data.id);
    /*var win=new Ext.Window({
     title:'更新',
     modal:true,
     height:160,
     width:350,
     layout:"form",
     labelAlign:'right',
     buttonAlign:'center',
     items:[{
      xtype:'textfield',
      fieldLabel:'title'
     },{
      xtype:'textarea',
      fieldLabel:'message',
      width:200
     }],
     buttons:[{
      text:'提交'
     }]
    });
    win.show();*/
   });
  }
 </script>
</head>
<body>
</body>
</html>

原创粉丝点击