Home > Web Front-end > JS Tutorial > How to dynamically generate columns with DataGird in jQuery EasyUI_jquery

How to dynamically generate columns with DataGird in jQuery EasyUI_jquery

WBOY
Release: 2016-05-16 15:06:44
Original
1383 people have browsed it

DataGird is used to display the data list in EasyUI. Sometimes it is necessary to display different columns as needed. For example, in permission management, different users can only view the list fields within their own permissions after logging in, which requires dynamic combination of DataGird. Column, the following introduces the method of dynamically generating columns by DataGird in EasyUI.

DataGird dynamically generates columns, which actually controls the columns attribute value of DataGird. Next, asynchronously call the data of background columns through ajax for binding.

<table id="dg"></table>
<script>
function easyUIDataGrid(medid) {
var $datagrid = {};
var columns = new Array();
$datagrid.title = "";
$datagrid.height = $(window).height() - 31;
$datagrid.width = $(window).width();
$datagrid.sortName = "dt";
$datagrid.sortOrder = "desc";
$datagrid.idField = "id";
var param = { "medid": medid };
$.ajax({
url: 'getCol.page',
type: 'post',
data: "medid=" + medid,
dataType: "json",
async: false,
success: function (returnValue) {
            //异步获取要动态生成的列 别名,宽度也可以
var arr = returnValue;
$.each(arr, function (i, item) {
columns.push({ "field": item.colname, "title": item.colalias, "width": 100, "sortable": true });
});
$datagrid.columns = new Array(columns);
$('#dg').datagrid($datagrid);
}
});
}
</script>
Copy after login

The above is the method of dynamically generating columns by DataGird in jQuery EasyUI introduced by the editor. I hope it will be helpful to everyone!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template