easyui的table如何動態添加行數據


需求是讀取excel表頭,動態的顯示出來。。。。

 

html:

<td>模板上傳:</td>
            <td class="text-left" style="width: 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="width: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:' 序號 ',
      width:150,
    formatter: function(val,rec,index){
    return index + 1;
    }
  },{
    field:'name',
    title:'中文字段',
    width:200
  },{field:'isjm',
    title:'是否加密 ',
    width:100,

  },{
  checkbox:'true',
  field:'Encrypt',
    title:'是否加密',
  width: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("出現意外的錯誤")
  }
  });
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM