jquery easyui 动态绑定数据列

function doSearch2() {
var strsql = $('#sssql').val();
$.ajax({
url: "../HttpHandler/DownloadHandler.ashx?action=StatDownLoadHHH&searchStrSql=" + encodeURI(strsql),
type: "POST",
error: function () {
$.messager.alert('错误', '操作失败!', 'error');
},
success: function (result) {
var result = eval('(' + result + ')');
//$('#tt').html(result.hmnr);

$('#tt').datagrid(result.columns);
}
});

// $('#tt').datagrid({
// columns: [[
// { field: 'itemid', title: 'Item ID', 80 },
// { field: 'productid', title: 'Product ID', 80 }
// ]],
// data: [
// { itemid: '张三', productid: '1' },
// { itemid: '李四', productid: '2' }
// ]
// });

// $('#tt').datagrid({
// data: [
// { itemid: '张三', productid: '1' },
// { itemid: '李四', productid: '2' }
// ]
// });

// $('#tt').datagrid('insertRow', {
// index: 1,
// row:{
// itemid:'fsfsdfs',
// productid:'KKKKKKPPoo'
// }

// });

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>软件管理</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css" />
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="DownloadRecordsStat.js" type="text/javascript"></script>

</head>
<body>

<div id="toolbar" style="height:100px">
<input id="sssql" class="easyui-textbox" data-options="multiline:true" value="select * from DOWNLOAD"
style="90%;height:100px" ></input>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch2()">查询</a>
</div>


<!-- <table id="dg"title="定性指标基础信息" class="easyui-datagrid"style="900px; height: 400px; padding-left: 200px;
pagination="true" rownumbers="true"fitcolumns="true"singleselect="true">
<thead>
<tr>
<th field ="firstname"width="50">定性指标级别</th>
<th field ="lastname"width="50">分数</th>
</tr>
</thead>
<tbody>
<tr>
<td>优秀</td>
<td>100</td>
</tr>
<tr>
<td>良好</td>
<td>80</td>
</tr>
<tr>
<td>一般</td>
<td>60</td>
</tr>
<tr>
<td>较差</td>
<td>50</td>
</tr>
</tbody>
</table> -->

<div id = "servicediv" style="100%;height:350px; overflow-y: auto">
<!--<table id="dgtbl" style="100%;height:450px" >
</table>-->

<table id="tt" title="Frozen Columns" class="easyui-datagrid" style="550px;height:250px"

singleSelect="true" iconCls="icon-save">
</table>

</div>

</body>
</html>

原文地址:https://www.cnblogs.com/panjun/p/4668138.html