easyui的table如何动态添加行数据

需求是读取excel表头,动态的显示出来。。。。

html:

<td>模板上传:</td>
            <td class="text-left" style=" 30%">
             <input type="file" class="form-control" data-required="1" name="file_name" id="fileName" value="" required="required">
             </td>

<table id="dg" class="easyui-datagrid" style="510px;height:250px" > </table> 

js:

$("#fileName").change(function(e){
  $.ajaxFileUpload({
  url: "***********",
  files: $(':file'),
  data: {},
  dataType: "json",
  contentType: 'text/json,charset=utf-8',
  success:function(data){
  if(data.length == 0){
  $('#file_examine').modal("show");
    $("#addTable").empty();
    alert("请检查读取的文件是否正确")
    return;
  }else{
    $('#dg').datagrid({
    columns:[[
      {field:'xh',
      title:' 序号 ',
      150,
    formatter: function(val,rec,index){
    return index + 1;
    }
  },{
    field:'name',
    title:'中文字段',
    200
  },{field:'isjm',
    title:'是否加密 ',
    100,

  },{
  checkbox:'true',
  field:'Encrypt',
    title:'是否加密',
  200
  }
  ]]
  });
  //easyui数据动态添加
  for(i=0;i<data.length;i++){
    $('#dg').datagrid('appendRow',{
    xh: 'new name',
    name: data[i],
    Encrypt: ''
  });
  }
  }
  },  
    error: function(data, status, e) {
      console.log("出现意外的错误")
  }
  });
})

原文地址:https://www.cnblogs.com/liglacier/p/11224214.html