一、SmartGrid排序与排序有关的属性包括:
如果需要客户端排序,只需要设置SortOption=”Client”即可。 override protected void OnInit(EventArgse)
{ this.SmartGrid1.ColumnSort += newSmartGridSortEventHandler(SmartGrid1_ColumnSort); }
二、懒加载
(1)懒加载事件说明 function myLoadOnDemand(grid,ev)
{ //这是示例,实际上数据可以一般会通过webservice behavior从服务器端取 var dom = new ActiveXObject("MSXML.DOMDocument"); dom.loadXML("< xml version='1.0' encoding='gb2312' ><detail><row k='0.6' editprop='o' no='CD034' name='TCL彩电' factory='TCL公司' address='福建' num='523' contact='老李'/><row k='0.5' editprop='o' no='CD096' name='康佳彩电' factory='康佳公司' address='四川' num='59' contact='李工'/><row k='0.5' editprop='o' no='RJ098' name='NC产品' factory='用友公司' address='北京' num='668' contact='王文京'/><row k='0.5' editprop='o' no='YJ908' name='联想电脑' factory='联想集团' address='北京' num='99' contact='柳传至'/><row k='0.5' editprop='o' no='LY897' name='路由器' factory='华为集团' address='北京' num='556' contact='赵川'/><row k='0.5' editprop='o' no='XS908' name='美格' factory='美格公司' address='美国' num='560' contact='开心'/><row k='0.5' editprop='A' no='XS988' name='三星显示器' factory='三星集团' address='韩国' num='668' contact='赵小窗'/><row k='0.5' editprop='A' no='XS786' name='ViewSonic' factory='ViewSonic' address='美国' num='444' contact='美丽'/><row k='0.5' editprop='A' no='YP343' name='奔腾III' factory='INTEL' address='美国' num='891' contact='开心'/><row k='0.5' editprop='A' no='CP789' name='毒龙' factory='MD' address='美国' num='88' contact='开心'/><row k='0.5' editprop='A' no='XS908' name='153V' factory='三星' address='韩国' num='44' contact='开心'/></detail>"); grid.append(dom.documentElement); //grid的append方法是追加数据 //grid的clear方法是清空当前Grid中的数据 //grid的fill方法是先清空当前Grid中的数据,然后再将数据加到Grid当中。 e.currentPageIndex ++; }
(2)懒加载事件示例代码(使用微软AJAX控件) function myLazyLoad(grid, e) {
//第一页在页面Page_Load中加载 varPageIndex; if(e.currentPageIndex <= 1) { PageIndex = 1; } else { PageIndex = e.currentPageIndex; } PageIndex = PageIndex + 1;? PageMethods.GetDemandDataString(PageIndex,e.pageSize,myLazyLoad_OnSucceeded, myLazyLoad_OnFailed); e.currentPageIndex = PageIndex; } //成功时的处理方法 functionmyLazyLoad_OnSucceeded(result) { vardom = new ActiveXObject("MSXML.DOMDocument"); dom.loadXML(result); vargrid = document.getElementById("<%=SmartGrid2.ClientID%>"); grid.append(dom.documentElement); } //失败时的处理方法 functionmyLazyLoad_OnFailed(error) { }
(3)懒加载后台代码示例 //懒加载某页数据 [System.Web.Services.WebMethod] public static string GetDemandDataString(intpageIndex,int pageSize) { XmlDocumentdoc; stringselectCmdString = "Select TOP(" +pageSize.ToString() + ") * FROM (Select*," + "ROW_NUMBER() OVER (ORDER BY GID) AS ROWNUM FROM Storage as tab) astab" + "Where tab.ROWNUM > " + ((pageIndex - 1) * pageSize).ToString() + "ORDER BY tab.ROWNUM"; DataSetcurrentDs = new DataSet(); using(SqlConnection currentConn = new SqlConnection(_connectionstring)) { //获取数据 currentConn.Open(); SqlDataAdaptercurrentSda = new SqlDataAdapter(selectCmdString,currentConn); currentSda.Fill(currentDs, "Storage"); doc =MyConvertDataTableToXML(currentDs.Tables["Storage_Goods"]); currentConn.Close(); } returndoc.InnerXml; } |