引用
<link href="../../dhtmlXGridScripts/dhtmlxgrid.css" rel="stylesheet" type="text/css" />
<link href="../../dhtmlXGridScripts/dhtmlxgrid_skins.css" rel="stylesheet" type="text/css" />
<script src="../../dhtmlXGridScripts/dhtmlxcommon.js" type="text/javascript"></script>
<script src="../../dhtmlXGridScripts/dhtmlxgrid.js" type="text/javascript"></script>
<script src="../../dhtmlXGridScripts/dhtmlxgridcell.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script> window.dhx_globalImgPath = "../../dhtmlxComboScripts/imgs/"; </script>
<script src="../../dhtmlXGridScripts/ext/dhtmlxgrid_srnd.js" type="text/javascript"></script>
<div id="gridbox1" style=" height:100%; width:500px"></div>
<script type="text/jscript">
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");
}
});
}
</script>
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);
}