首次不加载数据问题,必须搞明白如何才能不加载数据。根据Easu UI的官方API: http://www.jeasyui.com/documentation/
仔细观察DataGrid的事件当中有一个这样的描述:
根据这个我们给onBeforeLoad事件绑定如下的事件:
onBeforeLoad: function (param) { var firstLoad = $(this).attr("firstLoad"); if (firstLoad == "false" || typeof (firstLoad) == "undefined") { $(this).attr("firstLoad","true"); return false; } return true; }
这段代码的主要意思就是:去查找当前datagrid的属性firstLoad,如果是false或者没有,那么返回false。同时设置firstLoad属性为true,否则的话(认为是true)就返回true.
很显然第一次加载的时候默认肯定是没有这个属性的,那就会返回false。根据API我们已经知道,如果该事件返回false,datagrid就不会加载数据,从而在实现第一次不加载数据。而第二次的的时候firstLoad已经被设置为true,所以它会返回true,datagrid就会加载数据. 同时如果手动给table加上了firstLoad属性为true,那么datagrid也还是会在第一次加载时就load数据。
小例子:
$('#dg').datagrid({ title: "合同交互", fit: true, queryParams: { BeginTime: $('#date_beginTime').datetimebox("getValue"), EndTime: $('#date_endTime').datetimebox("getValue"), }, rownumbers: true, pagination: true, url: "/Contract/IPRequestsContractListByApplyId", pageSize: 20, singleSelect: true, columns: [ [ { field: "AddTime", title: "添加时间", 150, align: "center" }, { field: "Url", title: "访问地址", 1100, align: "center" }, { field: "ExceptionMessage", title: "异常信息", 300, align: "center" }, { field: "OutputContent", title: "输出内容", 1000, align: "center" }, { field: "Duration", title: "访问耗时", 100, align: "center" }, { field: "ip", title: "访问IP", 150, align: "center" } ] ], onBeforeLoad: function (param) { var firstLoad = $(this).attr("firstLoad"); if (firstLoad == "false" || typeof (firstLoad) == "undefined") { $(this).attr("firstLoad","true"); return false; } return true; } });