首页 > 代码库 > dhtmlx之dhtmlXGrid显示数据 --大数据

dhtmlx之dhtmlXGrid显示数据 --大数据

引用

     <link href="http://www.mamicode.com/dhtmlXGridScripts/dhtmlxgrid.css" rel="stylesheet" type="text/css" />
    <link href="http://www.mamicode.com/dhtmlXGridScripts/dhtmlxgrid_skins.css" rel="stylesheet" type="text/css" />
    <script src="http://www.mamicode.com/dhtmlXGridScripts/dhtmlxcommon.js" type="text/javascript"></script>
    <script src="http://www.mamicode.com/dhtmlXGridScripts/dhtmlxgrid.js" type="text/javascript"></script>
    <script src="http://www.mamicode.com/dhtmlXGridScripts/dhtmlxgridcell.js" type="text/javascript"></script>
    <script src="http://www.mamicode.com/Scripts/jquery-1.4.4.js" type="text/javascript"></script>
   <script> window.dhx_globalImgPath = "../../dhtmlxComboScripts/imgs/"; </script>
    <script src="http://www.mamicode.com/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);
        }

dhtmlx之dhtmlXGrid显示数据 --大数据