jQuery Easyui學習教程之實現datagrid在沒有資料時顯示相關提示內容_jquery

來源:互聯網
上載者:User

本樣本實現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>');  }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.