我使用 Extjs 3.4。在服务器端,我有返回具有随机结构(不同列、行)的数据表的方法。
我想准备一个带有 extjs 网格的 javascript 文件,它可以获取任何数据表并在此网格中显示它。
(当我知道数据表结构时,我将 jsonReader 创建到数据网格,并从数据表发送带有日期的 json。但是在这里,我不知道如何解决它)
有可能做到吗?如果是,如何?
public static List<Dictionary<string, object>> ToJsonStructure(this DataTable table)
{
if (table == null) throw new ArgumentNullException("table");
List<Dictionary<string, object>> data = new List<Dictionary<string, object>>();
Dictionary<string, object> obj;
foreach (DataRow r in table.Rows)
{
obj = new Dictionary<string, object>();
foreach (DataColumn c in table.Columns)
{
obj[c.ColumnName] = r[c.ColumnName];
}
data.Add(obj);
}
return data;
}
在这里演示http://ext4all.com/post/extjs-3-how-to-put-c-datatable-to-extjs-grid