easyui 数据表格datagrid动态列代码

$('#searchForm').form("submit", {
  url : WINDOW_CONTEXT_PATH+'/data/roleList.action',
  dataType:'json',
  success : function(data) {
   var result = $.parseJSON(data);
   if (result.success) {
    var columns=new Array();
          var cls=result.rows.columns;
          for(var i=0;i<cls.length;i++){
           var column={}; 
              column["title"]=cls[i].title; 
              column["field"]=cls[i].field; 
              column["width"]=100;
              column["align"]='center';
              columns.push(column);
    };
          grid = $('#grid').datagrid({
              idField : 'roleId',
     striped : false,
     rownumbers : true,
     pagination : true,
     singleSelect : false,
     pageSize : 10,
     pageList: [10, 20],

     fitColumns: true,
     striped:true,
     toolbar:"#toolbar",
     frozenColumns : [[{
      title : '角色ID',
      field : 'roleId',
      width : 100,
      sortable:true
     }]],
              columns : [ 
                  columns 
              ], 
              rownumbers:true}).datagrid('loadData',result.rows.rows).datagrid('clearSelections'); 
   } else {
    $.messager.alert('提示', result.error.msg, 'error');
   }
  }   
 });

你可能感兴趣的:(JavaScript)