Home  >  Article  >  Web Front-end  >  Layui implements the method of adding a row by clicking a button

Layui implements the method of adding a row by clicking a button

尚
forward
2020-06-12 17:55:323389browse

Layui implements the method of adding a row by clicking a button

1. Use ajax request to retrieve the data and store it in a variable, and assign the variable to the data of the table

  var organData = [];
  $.ajax({
        url: baseUrl+'/org/getSysOrgList'
        ,type:"POST"
        ,async:false
        ,dataType:"json"
        , success: function(result){
            organData=result;
        }
  });

2. Pass the data through the data method

table.render({
        elem: '#organ-manage-list'
        ,data:organData
        ,method:'POST'
        ,cols: [[
         {field: 'orgCode', width: 100, title: '组织编码', sort: true}
        ,{field: 'orgName', title: '组织名称', width: 200}
        ,{field: 'pOrgCode', title: '上级行政组织', width: 100}
        ,{field: 'orgModal', title: '组织形态', width: 100}
        ,{field: 'isSelfOrg', title: '是否核算组织', width: 100}
        ,{field: 'status', title: '启/停用', width: 100}
        ,{field: 'updTime', title: '更新时间', width: 200}
        ,{title: '操作',align:'center', fixed: 'right', toolbar: '#table-organ-operator'}
        ]]
        ,page: true
        ,limit: 10
        ,height: 'full-220'
        ,done: function(res, curr, count){
              //如果是异步请求数据方式,res即为你接口返回的信息。
              //如果是直接赋值的方式,res即为:{data: [], count: 99} data为当前页数据、count为数据总长度
                sessionStorage.setItem("countTemp",count);
              }
        ,text: '对不起,加载出现异常!'
  });

For more layui knowledge, please pay attention to the PHP Chinese websitelayuitutorial column

The above is the detailed content of Layui implements the method of adding a row by clicking a button. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete