在網上查了很長時間沒有找到解決方法,乾脆自已檢視一下程式碼來解決吧,隨是壓縮過的,不過也還是好查的,工夫不負有心人,終於解決了,方法如下:
一、我們先讓表格自適應寬度
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Basic DataGrid - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="../../themes/bootstrap/easyui.css"> <link rel="stylesheet" type="text/css" href="../../themes/icon.css"> <link rel="stylesheet" type="text/css" href="../demo.css"> <script type="text/javascript" src="../../jquery.min.js"></script> <script type="text/javascript" src="../../jquery.easyui.min.js"></script> </head> <body> <h2>Basic DataGrid</h2> <div class="demo-info"> <div class="demo-tip icon-tip"></div> <div>The DataGrid is created from markup, no JavaScript code needed.</div> </div> <div style="margin:10px 0;"></div> <table class="easyui-datagrid" data-options="singleSelect:true,collapsible:true,url:'datagrid_data1.json',method:'get',fitColumns:'true'"> <thead> <tr> <th data-options="field:'itemid',width:300">Item ID</th> <th data-options="field:'productid',width:300">Product</th> <th data-options="field:'listprice',width:300,align:'right'">List Price</th> <th data-options="field:'unitcost',width:300,align:'right'">Unit Cost</th> <th data-options="field:'attr1',width:300">Attribute</th> <th data-options="field:'status',width:300,align:'center'">Status</th> </tr> </thead> </table> <script> $(window).resize(function () { $('#tt').datagrid('resize'); }); </script> </body> </html>
二、修改jquery.easyui.min.js這個檔案來解決滾動條問題
function _4bf(_4c0){ var opts=$.data(_4c0,"datagrid").options; var dc=$.data(_4c0,"datagrid").dc; var wrap=$.data(_4c0,"datagrid").panel; var _4c1=wrap.width()+20; var _4c2=wrap.height(); var view=dc.view; var _4c3=dc.view1; var _4c4=dc.view2; var _4c5=_4c3.children("div.datagrid-header"); var _4c6=_4c4.children("div.datagrid-header"); var _4c7=_4c5.find("table"); var _4c8=_4c6.find("table"); view.width(_4c1); var _4c9=_4c5.children("div.datagrid-header-inner").show(); _4c3.width(_4c9.find("table").width()); if(!opts.showHeader){ _4c9.hide(); }
可以看到我在 7001 行處加上了一個+20,這樣讓寬度正好覆蓋滾動條
大家如果有更好的方法留言給我呀