DataGrid首次进入页面时,不加载任何数据[转]

首次不加载数据问题,必须搞明白如何才能不加载数据。根据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: "添加时间", width: 150, align: "center" },
                    { field: "Url", title: "访问地址", width: 1100, align: "center" },
                    { field: "ExceptionMessage", title: "异常信息", width: 300, align: "center" },
                    { field: "OutputContent", title: "输出内容", width: 1000, align: "center" },
                    { field: "Duration", title: "访问耗时", width: 100, align: "center" },
                    { field: "ip", title: "访问IP", width: 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;
            }

     });

 

posted @ 2019-03-11 10:48  三号小玩家  阅读(1248)  评论(0)    收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840