對easyui datagrid進行擴充,當捲軸拉直最下面就非同步載入資料。

來源:互聯網
上載者:User

以下方法是通用的,只要把datagrid定義為全域的即可,其他部分的代碼不用進行修改!

可以把以下代碼放入到一個單獨的js檔案,然後再需要的頁面引入即可!

$(function(){try{$(".datagrid-body").scroll(function(){  var sheight = $(this)[0].scrollHeight;          var top=$(this)[0].scrollTop;          var height=$(this).height();          //判斷是否到達底部          document.title='top:'+(top+height)+' heigth:'+(sheight-20);          if((top+height)+20==sheight){        document.title=datagrid.datagrid('options').url;        //請求json        //page;// 當前頁//rows;// 每頁顯示記錄數//拼接表單的值var url=datagrid.datagrid('options').url;url+='?params=xxx';var params='';$("#searchForm").find('input').each(function(index){var obj=$(this);if(obj.prop('name')!=''&&obj.val()!=''){params+='&'+obj.prop('name')+'='+obj.val();}});//擷取頁碼、每次預設載入10條var num=10;//擷取行數var row=datagrid.datagrid('getRows').length;var page=(row/num)+1; //求出下一頁//$.post();url+=params+'&page='+page+'&rows=10';//請求資料$.post(url,function(data){var json=$.parseJSON(data).rows;for(var i=0;i<json.length;i++){//自動拼接欄位和賦值var row='';for(var item in json[i]){row+='"'+item+'":'+'"'+json[i][item]+'",';}row=row.substring(0,row.length-1);row='{'+row+'}';row=$.parseJSON(row);datagrid.datagrid("appendRow",row);}});                }else{document.title='捲軸沒有到達底部';    }});}catch(e){alert(e);}});

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.