本樣本實現easyui datagrid載入/查詢資料時,如果沒有相關記錄,則在datagrid中顯示沒有相關記錄的提示資訊,效果如下圖所示
本執行個體要實現如下圖所示的效果:
本樣本easyui版本為1.3.4,如果運行後沒有效果,自己檢查easyui版本
不同版本對appendRow和mergeCells支援不一樣,參數不一致什麼的。
無法隱藏分頁導航容器,可以用chrome開發工具或者firebug查看分頁導航容器的樣式和原始datagrid table表格的關係。
原始碼如下
$(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沒有資料顯示無資料提示資訊', width: 550, columns: [[{ field: 'itemid', width: 80, title: 'Item ID' }, { field: 'productname', width: 100, editor: 'text', title: 'Product Name' }, { field: 'listprice', width: 80, align: 'right', title: 'List Pirce' }, { field: 'unitcost', width: 80, align: 'right', title: 'Unit Cost'}]] }); }); product.json{"total":0,"rows":[]}
以上所述是小編給大家介紹的jQuery Easyui學習教程之實現datagrid在沒有資料時顯示相關提示內容的全部敘述,希望對大家有所協助,如果大家有任何問題歡迎給我留言,小編會及時回複大家的!
下面給大家介紹 jQuery EasyUI datagrid 無記錄時,增加"暫無資料"提示
在 datagrid 的onLoadSuccess事件進行操作:
onLoadSuccess: function (data) { if (data.total == 0) { var body = $(this).data().datagrid.dc.body2; body.find('table tbody').append('<tr><td width="' + body.width() + '" style="height: 35px; text-align: center;"><h1>暫無資料</h1></td></tr>'); }}