ExtJS's grid components, although in any case, are very good and powerful, but there are always some applications do not need so many features, such as the site's message list, developers want only a simple <li> or <table> list, At this time xtemplate seems very useful.
This article will explain how to use xtemplate to interact with the server side to generate a list of data, plus no refresh paging functionality (ExtJS does not provide paging functionality by default xtemplate)
1. Do some preparatory work, write a generic class (adapted from Lao Zhang's Pagedata), for WCF to return the paging data to ExtJS
Code
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
/// <summary>
///PageData 的摘要说明
/// </summary>
///
[DataContract]
public class PageData<T>
{
[DataMember]
public int RecordCount { set; get; }
[DataMember]
public int PageSize { set; get; }
[DataMember]
public int PageCount { set; get; }
[DataMember]
public int CurrentPageIndex { set; get; }
[DataMember]
public T Data { set; get; }
}
2.DateTime serialization problem because. NET serializes datetime, no matter how hard you try, as long as it's a datetime type, you can end up generating strings like "f_date": "\/date (1221023588109+0800) \/" , ExtJS is not recognized correctly! For this we need a third party gadget Newtonsoft.Json.dll for serializing the DateTime, which is specifically used to serialize the object to a Json string. Importantly, with this serialized datetime string, ExtJS can be identified (note: Baidu search "Newtonsoft.json" can easily find more than n download, download directly to the project reference can be added)
3. Write specific entity class T_guestbook, directly in the database built, dragged into the dbml can be, the main code is as follows (note that to set DBML serialization property is "one-way", otherwise vs will not automatically for class and the members of the serialization label):
Code
[Table (name=) dbo. T_guestbook ")]
[DataContract ()]
Public partial class t_guestbook:inotifypropertychanging, INotifyPropertyChanged
{
[Column (storage= "_f_id", Autosync=autosync.oninsert, dbtype= "Int not NULL IDENTITY", Isprimarykey=true, isdbgenerated =true)]
[DataMember (Order=1)]
public int f_id
{
}
[Column (storage= "_f_ip", dbtype= "NVarChar not NULL", Canbenull=false)]
[DataMember (order=2)]
public string F_ip
{
}
[Column (storage= "_f_date", dbtype= "DateTime not NULL")]
[DataMember (Order=3)]
Public System.DateTime F_date
{
}
[Column (storage= "_f_content", dbtype= "NVarChar (1000) Not NULL", Canbenull=false)]
[DataMember (order=4)]
public string F_content
{
}
[Column (storage= "_f_reply", dbtype= "NVarChar (1000) Not NULL", Canbenull=false)]
[DataMember (Order=5)]
public string f_reply
{
}
}