Ext.grid.Panel 从后台获取数据源和数据格式详解

简介: 1 Ext.create("Ext.grid.Panel", { 2 title: "userInfo", 3 store: Ext.

 

 1  Ext.create("Ext.grid.Panel", {
 2                 title: "userInfo",
 3                 store: Ext.data.StoreManager.lookup("userInfoStore"),
 4                 columns: [
 5                             { header: "UserName", dataIndex: "UserName", flex: 1 },
 6                             { header: "Phone", dataIndex: "Phone", flex: 1 },
 7                             { header: "Eamil", dataIndex: "Eamil", flex: 1 },
 8                             { header: "QQ", dataIndex: "QQ", flex: 1 },
 9                             { header: "Addr", dataIndex: "Addr", flex: 1 },
10                             { header: "Department", dataIndex: "Department", flex: 1 }
11                             ],
12                 features: [{ ftype: 'grouping'}],
13                 width: 600,
14                 heigth: 400,
15                 renderTo: Ext.getBody()
16             });
17         });

 

 

前台extjs代码:

 Ext.onReady(function () {
 
  1.定义userInfo类
           
 1  Ext.define("userInfo", {
 2                 extend: "Ext.data.Model",
 3                 fields: [
 4                 { name: "UserName", type: "string" },
 5                 { name: "Phone", type: "string" },
 6                 { name: "Eamil", type: "string" },
 7                 { name: "QQ", type: "string" },
 8                 { name: "Addr", type: "string" },
 9                 { name: "Department", type: "string"}]
10             });

 

  2.定义store用来装后台返回到前台的数据,并作为Ext.grid.Panel的数据源
   
 1  var store = Ext.create("Ext.data.Store", {
 2                 storeId: "userInfoStore",
 3                 model: "userInfo",
 4                 groupField: "Department", //store数据通过Department进行分组存储
 5                 autoLoad: true,
 6                 proxy: {
 7                     type: "ajax",
 8                     url: "test2.aspx",
 9                     reader: {
10                         type: "xml",
11                         record: "Table"//表明xml的有效数据从哪里开始
12                     }
13                 }
14             });

 

           
  3.创建Ext.grid.Panel进行数据的分组显示
           
后台数据的获取(这里定了一个中间类)
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Data.SqlClient;
 6 using System.Data;
 7 using System.Web.Configuration;
 8  
 9 /// <summary>
10 ///test 的摘要说明
11 /// </summary>
12 public class testCs
13 {
14     private SqlConnection con = null;
15     private DataSet ds = null;
16     private SqlCommand cmd = null;
17     private string connStr = string.Empty;
18     private SqlDataAdapter da = null;
19     public testCs()
20     {
21         connStr = WebConfigurationManager.ConnectionStrings["OMSDB"].ConnectionString;
22     }
23     private void CloseConnection()
24     {
25         if (con.State == ConnectionState.Open)
26         {
27             con.Close();
28         }
29     }
30     private void OpenConnection()
31     {
32         if (con.State == ConnectionState.Closed)
33         {
34             con.Open();
35         }
36     }
37     public DataSet GetData(string sql)
38     {
39         using (con = new SqlConnection(connStr))
40         {
41             using (da = new SqlDataAdapter(sql, con))
42             {
43                 try
44                 {
45                     ds = new DataSet();
46                     OpenConnection();
47                     da.Fill(ds);
48                     return ds;
49                 }
50                 catch (Exception ex)
51                 {
52                     throw new Exception(ex.Message, ex);
53                 }
54                 finally
55                 {
56                     CloseConnection();
57                 }
58             }
59         }
60     }
61 }

 

服务器页面的后台代码:
1   Response.ContentType = "application/xml;charset=utf-8";//一定要记得设置这个,因为默认的情况是以html格式返回的
2         testCs getdata = new testCs();
3         ds = new DataSet();
4         ds = getdata.GetData("SELECT UserName,Phone,Eamil,QQ,Addr,Department FROM dbo.TEST_TB");
5         Response.Write(ds.GetXml());


转:http://blog.sina.com.cn/s/blog_62fda93c01016eet.html

目录
相关文章
|
机器学习/深度学习 存储 NoSQL
Graph RAG: 知识图谱结合 LLM 的检索增强
RAG(Retrieval Argumented Generation)这种基于特定任务/问题的文档检索范式中,我们通常先收集必要的上下文,然后利用具有认知能力的机器学习模型进行上下文学习(in-context learning),来合成任务的答案。这次,我们借助 LLM 的力量,强化下 RAG。
2869 0
Graph RAG: 知识图谱结合 LLM 的检索增强
|
存储 固态存储 安全
阿里云服务器最新收费标准与云服务器活动价格参考
阿里云服务器最新收费标准参考,入门级1核2G配置收费标准最低64.06/月,2核4G收费标准最低68.0/月,4核8G收费标准最低216.0/月,8核16G收费标准最低432.0/月,目前在阿里云的活动中,2核2G最低36元1年,2核4G企业最低199元1年,2核8G活动价格最低652.32元1年,4核8G活动价格最低955.58元1年,8核16G活动价格最低3815.03元1年。更多不同实例规格及配置的阿里云服务器最新收费标准,活动价格如下文所示。
|
安全 网络安全 开发者
2024 全网热门的服务器面板测评推荐
在当今数字化时代,服务器管理的效率和便捷性对于企业和开发者来说至关重要。服务器面板作为服务器管理的得力助手,能够极大地简化操作流程,提高管理效能。本
2024 全网热门的服务器面板测评推荐
|
12月前
|
弹性计算 数据管理 应用服务中间件
活动实践 | 借助OSS搭建在线教育视频课程分享网站
本教程指导用户在阿里云ECS实例上搭建在线教育网站,包括重置ECS密码、配置安全组、安装Nginx、创建网站页面、上传数据至OSS、开通OSS传输加速、配置生命周期策略及清理资源等步骤,实现高效、低成本的数据管理和网站运营。
活动实践 | 借助OSS搭建在线教育视频课程分享网站
|
存储 弹性计算 NoSQL
个人和企业购买阿里云服务器配置选择经验及注意事项分享
无论是个人还是企业用户,需要搭建网站或者部署APP、数据库等项目,买个价格便宜且适合自己云服务器是必不可少的,好多个人和企业用户买阿里云服务器只看价格,哪个便宜就买哪个,殊不知云服务器实例规格不同,性能差异是很大的,另外配置也要根据自己的需求来选择合适的,选择1核2G、2核2G这些入门级配置是无法满足大型网站或其他项目需求的。本文为大家分享几点阿里云个人和企业购买云服务器的相关经验及注意事项,以供参考。
1872 0
个人和企业购买阿里云服务器配置选择经验及注意事项分享
|
安全 Devops 网络安全
【天幕系列 04】职业发展指南:顶尖证书如何提升你的职业竞争力
【天幕系列 04】职业发展指南:顶尖证书如何提升你的职业竞争力
214 5
|
图形学
Unity教程:GUI 界面开发
UI概述: UI永远是显示在屏幕的最前面上,不受变形、碰撞、光照的影响GUI概述:GUI是Graphical User Interface的缩写。Unity的图形界面系统能容易和快速创建出各种交互界面。
2542 0
|
Android开发
layout_weight属性的再认识
package cc.testlayout_weight; import android.os.Bundle; import android.app.
760 0