easy ui JS 實現Grid

來源:互聯網
上載者:User

標籤:js   easy ui   grid   javascript   html   

easy ui的grid的實現方式有兩種 

1.是在網頁中實現 (這裡不說了 我感覺還是在js中實現操作起來比較方便)

2.在JS中實現

好了我們就來說說如何在JS中實現的GRID

第一步就是我們要引用easy ui 的JS  

<script type="text/javascript" src="../JS/jquery.min.js"></script><script type="text/javascript" src="../JS/jquery.easyui.min.js"></script>
好了 下面就是HTML 的代碼

<table id="dg"></table> 
只需要給一個 table定義一個ID

好啦我們開始定義我們JS裡面的grif的實現方法

var lastIndex;function datagridload(){$('#dg').datagrid({     rownumbers:true,singleSelect:true,pagination:true,//分頁空間        url:'datagrid_data1.json',          loadMsg:"正在努力載入資料,請稍後...",title:'家庭人員列表(*紅色字型為年齡較小人員)',          nowrap: true,        striped : true,        border: true,         collapsible:false,//是否可摺疊的          remoteSort:false,        idField:'fldId', height:500,    columns:[[            {field:'code',title:'登陸名稱',width:50},            {field:'name',title:'姓名',width:100},            {field:'age',title:'年齡',width:20,align:'right'} ,{field:'six',title:'性別',width:20,align:'right'}  ,{field:'birthday',title:'生日',width:100,align:'right'}  ,{field:'idnumber',title:'證件號碼',width:100,align:'right'}  ,{field:'phone1',title:'連絡方式1',width:100,align:'right'},{field:'phone2',title:'連絡方式2',width:100,align:'right'}  ,{field:'status',title:'狀態',width:40,align:'right'} , {field:'fposition',title:'家庭職位',width:100,align:'right'},{field:'industry',title:'從事行業',width:100,align:'right'}    ]] , rowStyler: function(index,row){                    if (row.age < 20){                        return 'color:red;font-weight:bold;';                    }                },toolbar: [{text:'新增使用者',iconCls: 'icon-add',handler: adduser},'-',{text:'修改使用者',iconCls: 'icon-edit',handler: function(){ var row = $('#dg').datagrid('getSelected');//擷取選中行 if(row==null){          $.messager.alert('提示','請選擇一行資訊!','warning');      }else{       updateuser();  }}},'-',{text:'刪除使用者',iconCls: 'icon-remove',handler: function(){ var row = $('#dg').datagrid('getSelected');//擷取選中行 if(row==null){          $.messager.alert('提示','請選擇一行資訊!','warning');      }else{  $.messager.confirm('提示','確定要刪除'+row.name+'使用者!',deleteuser);  }}}] ,onClickRow:function(rowIndex){                      if (lastIndex != rowIndex){                          $('#dg').datagrid('endEdit', lastIndex);                          $('#dg').datagrid('beginEdit', rowIndex);                      }                      lastIndex = rowIndex;                 },onSelect:function(rowIndex,rowData){//使用者選擇一行觸發事件 //alert('Item ID:'+rowData.code+"\nPrice:"+rowData.name);}});var p = $('#dg').datagrid('getPager');      $(p).pagination({          pageSize: 10,//每頁顯示的記錄條數,預設為10          pageList: [5,10,15],//可以設定每頁記錄條數的列表loading:true,        beforePageText: '第',//頁數文字框前顯示的漢字          afterPageText: '頁    共 {pages} 頁',          displayMsg: '當前顯示 {from} - {to} 條記錄   共 {total} 條記錄',          /*onBeforeRefresh:function(){             $(this).pagination('loading');             alert('before refresh');             $(this).pagination('loaded');         }*/onSelectPage:function(pageNumber, pageSize){var url="datagrid_data"+pageNumber+".json";//把URL的路徑經過Ajax傳入後台    $('#dg').datagrid('load',url);  }    }); }
分頁的實現也在裡面 可以研究一下有興趣的

下面就是JS的載入了

$(document).ready(function(){  //JS載入datagridload();});
好了 我們就實現了簡單的grid載入資料了

在說一下 我們的JSON檔案 格式

{"total":13,"rows":[{"code": "xiaxia","name":"haha","age":"24","six":"女","birthday":"1991-02-22","idnumber":"3203211199108134216","phone1":"12345666445","phone2":"","status":"無","fposition":"家人","industry":"會計"},{"code": "xiaokang","name":"huhu","age":"24","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"lisi","age":"15","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"王武","age":"60","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"1212","age":"11","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"黑色的機會","age":"77","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"hdjh ","age":"77","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"dfgdfgdf","age":"77","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"ereer","age":"78","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"},{"code": "xiaokang","name":"dsffd","age":"77","six":"男","birthday":"1991-08-13","idnumber":"3203211199108134216","phone1":"18361912397","phone2":"","status":"無","fposition":"家人","industry":"軟體"}]}






easy ui JS 實現Grid

聯繫我們

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