easy ui datagrid在没有数据时显示相关提示内容

$(function () {
    $('#dg').datagrid({
        fitColumns: true,
        url: 'product.json',
        pagination: true,
        pageSize: 3,
        onLoadSuccess: function (data) {
            if (data.total == 0) {
                //添加一个新数据行,第一列的值为你需要的提示信息,然后将其他列合并到第一列来,注意修改colspan参数为你columns配置的总列数
                $(this).datagrid('appendRow', { itemid: '<div style="text-align:center;color:red">没有相关记录!</div>' }).datagrid('mergeCells', { index: 0, field: 'itemid', colspan: 4 })
                //隐藏分页导航条,这个需要熟悉datagrid的html结构,直接用jquery操作DOM对象,easyui datagrid没有提供相关方法隐藏导航条
                $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
            }
            //如果通过调用reload方法重新加载数据有数据时显示出分页导航容器
            else $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
        },
        title: 'easyui datagrid没有数据显示无数据提示信息',
         550,
        columns: [[{ field: 'itemid',  80, title: 'Item ID' },
         { field: 'productname',  100, editor: 'text', title: 'Product Name' },
         { field: 'listprice',  80, align: 'right', title: 'List Pirce' },
         { field: 'unitcost',  80, align: 'right', title: 'Unit Cost'}]]
    });
});

文章出处:http://www.cnblogs.com/huyong/p/4896958.html

原文地址:https://www.cnblogs.com/foreverfendou/p/5091511.html