asp.net Ext grid 표시 목록

7091 단어
프런트 페이지:
 
  




gird








<br>function ready() <br>{ <br>Ext.BLANK_IMAGE_URL="ExtJS/docs/resources/s.gif"; // , ( ) <br>var url="myGridJson.aspx?Param=select"; <br>var sm=new Ext.grid.CheckboxSelectionModel();// <br>var cm=new Ext.grid.ColumnModel // ( Employees ) <br>([ <br>sm,// , <br>new Ext.grid.RowNumberer({header:" ",width:100}),// <br>{header:' ',dataIndex:'EmployeeID',sortable:true, width:100}, <br>{header:' ',dataIndex:'LastName',sortable:true,width:100,editor:new Ext.form.TextField()}, <br>{header:' ',dataIndex:'FirstName',sortable:true,width:100,editor:new Ext.form.TextField()}, <br>{header:' ',dataIndex:'BirthDate',sortable:true,width:100,renderer:Ext.util.Format.dateRenderer('Y m d ')} //,renderer:Ext.util.Format.dateRenderer('Y m d ') <br>]); <br>// cm.defaultSortable=true; // <br>var fields= // <br>[ <br>{name:"EmployeeID",mapping: 'EmployeeID'}, <br>{name:"LastName",mapping: 'LastName'}, <br>{name:"FirstName",mapping:'FirstName'}, <br>{name:"BirthDate",mapping:'BirthDate',type:'date'} <br>]; <br>//store Ext grid store <br>var store=new Ext.data.Store //JsonReader totalProperty ,root json <br>({ <br>proxy:new Ext.data.HttpProxy({url:url}),//proxy <br>reader:new Ext.data.JsonReader //reader <br>({ <br>totalProperty:"totalCount",root:"root",//totalCount <br>fields:fields //fields 4 , EmployeeID LastName ... <br>}) // ColumnModel dataIndex , ColumnModel <br>// remoteSort:true // store.remoteSort = true , sort ,dir,sort dir <br>}); // , <br>store.load({params:{start:0,limit:3}}); // start limit , toolbar pageSize <br>var pagingBar=new Ext.PagingToolbar // toolbar <br>({ <br>displayInfo:true, <br>emptyMsg:" ", <br>displayMsg:" {0} {1} , {2} ", <br>store:store, <br>pageSize:3 // pageSize (pageCount) pageCount/pageSize <br>}); <br>var grid=new Ext.grid.GridPanel <br>({ <br>// el:"testGrid", <br>id:"MenuGrid", <br>title:" ", <br>// autoWidth:true, <br>autoHeight:true, <br>width:550, <br>//height:300, // height, height 0, <br>renderTo:document.body, <br>layout:"fit", <br>frame:true, <br>border:true, <br>// autoScroll:true, <br>sm:sm, //GridPanel , , , GridPanel <br>cm:cm, <br>store:store, <br>// viewConfig:{forceFit: true}, true grid ,grid , <br>bbar:pagingBar <br>}); <br>grid.addListener('sortchange', sortchangeFn); // grid 'sortchange' , , ( remoteSort:true) <br>// ( store.reload({params:{start:0,limit:3}}) ) <br>function sortchangeFn(grid, sortinfo) <br>{ <br>//alert(' '+ sortinfo.field + " " + sortinfo.direction); <br>remoteSort:true <br>store.reload({params:{start:0,limit:3}}); // store.reload , sort ,dir dir desc->asc,asc->desc <br>} <br>} <br>Ext.onReady(ready); <br>







백그라운드 코드:
 
  
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace ExtPra
{
public partial class myGridJson : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region
int pagesize = 20;
int start = 1;
string field, asc_desc;
if (string.IsNullOrEmpty(Request["sort"]))
{
field = "EmployeeID";
asc_desc = "asc";
}
else
{
field = Request["sort"];
asc_desc = Request["dir"];
}
if (!string.IsNullOrEmpty(Request["limit"]))
{
pagesize = int.Parse(Request["limit"]);
start = int.Parse(Request["start"]);
}
start = start / pagesize;
start += 1;
#endregion
string strSql = string.Format("select EmployeeID, LastName,FirstName,BirthDate from Employees where EmployeeID between ({0}-1)*{1}+1 and {0}*{1} order by {2} {3} ",start,pagesize,field,asc_desc);
string strConnection = "Data Source=.;Initial Catalog=Northwind;User ID=sa;password=sa";
SqlConnection con = new SqlConnection(strConnection);
SqlDataAdapter da = new SqlDataAdapter(strSql, con);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
string json = "";
IList mList = new List();
try
{
foreach (DataRow row in ds.Tables[0].Rows)
{
Hashtable ht = new Hashtable();
foreach (DataColumn col in ds.Tables[0].Columns)
{
ht.Add(col.ColumnName, row[col.ColumnName]);
}
mList.Add(ht);
}
json = JavaScriptConvert.SerializeObject(mList);
}
catch (Exception ee)
{
string error = ee.Message;
}
// int count = ds.Tables[0].Rows.Count;
int count = 9;
json = "{totalCount:" + count + ",root:" + json + "}";
Response.Write(json);
Response.End();
}
}
}

좋은 웹페이지 즐겨찾기