引用
var mygrid; // 定义mygrid
$(function () {
mygrid = new dhtmlXGridObject('gridbox1');
mygrid.setHeader("标题一,标题二,标题三"); // 设置grid的头
mygrid.setInitWidths("150,150,150")
mygrid.setColTypes("cntr,ro,ed");
mygrid.setColAlign("center,center,center");
mygrid.setColSorting("na,str,str");
mygrid.setSkin("dhx_skyblue");
mygrid.setColumnColor("#B0CDAF");
mygrid.init(); // 初始化
mygrid.enableSmartRendering(true); //加载大数据
mygridjiazai(); // 调用方法,加载数据(数据库查询)
});
function mygridjiazai() {
$.ajax({
type: "POST",
url: "/Main/GetDemoData",
cache: false,
success: function (result) {
mygrid.parse(result, "jsarray");
}
});
}
public ActionResult GetDemoData()
{
ArrayList jsonList = new ArrayList();
foreach (DataRow dr in Demo.DemoData().Rows)
{
jsonList.Add(new ArrayList() { dr["ID"], dr["Name"], dr["Content"] });
}
// string json = Demo.DataTable2Json(Demo.DemoData());
return Json(jsonList, JsonRequestBehavior.AllowGet);
}