首页 > 技术文章 > layui框架中左树右表只刷新数据不刷新页面的方法

zk-94872 2021-01-06 11:46 原文

layui框架中左树右表只刷新数据不刷新页面的方法

  table.render({
   elem: '#userdata'
  ,url: '/fjcj/jcxxMst/pageQuery'
  ,method:'post'
  ,cols: [[
        {type: 'numbers', title: '序号', width: '40'}
      ,{field: 'xm', width: 100, title: '姓名'}
      ,{field: 'acc', width: 100, title: '辅警账号'}
      ,{field: 'xb', width: 100, title: '性别', width: 90,templet:'#userSex'}
      ,{field: 'sfzh', width: 100, title: '身份证号',width: '180'}
      ,{field: 'ryzt', title: '状态', width: 60, templet:'#userStatus'}
      ,{title: '操作', align: 'center', width: '200', toolbar: '#table-system-user'}
  ]]
  ,page: true
  ,limit: 10
  ,limits: [10, 20, 30 ,40 ,50]
  ,text: {none: '暂无数据'}
  ,done: function(){
       element.render('progress')
  }
});
  table.on('tool(userdata)', function(obj){
   var data = obj.data;
   if(obj.event === "del"){
           layer.confirm("你确定要删除该用户吗?",{btn:['是','否']},
             function(){
                   $.post("/fjcj/jcxxMst/delete",{"id":data.id},function (res){
                      if(res.success){
                          layer.msg("删除成功",{time: 400},function(){
                        obj.del();
                              dataReload(data);  //只刷新数据不刷新页面
                           
                          });
                      }else{
                          layer.msg(res.message, {icon: 5});
                      }
                  });
              }
          )
      }


  });
  //监听搜索
  form.on('submit(searchForm)', function (data) {
      selectUserIds ="";
      dataReload(data);
  });

  function dataReload(data){
      var field = data.field;
     table.reload('userdata', {
        page:{
           curr:1
        },
        where: field
      });
}



推荐阅读