GithubHelp home page GithubHelp logo

Comments (3)

jichuanan avatar jichuanan commented on June 1, 2024 5

调查发现,treeTable重载数据时,会先加载显示顶层节点,然后根据重载数据前保存的子节点展开状态,重新展开需要展开的子节点。在顶层节点比较少,没有展开子节点没有滚动条的情况下,如果重载数据前有滚动条滚动在某个位子,重载数据后只显示顶层节点,还没有自动展开子节点时,滚动条就消失了,自动展开子节点时重新出现滚动条就会处在顶部,无法保持在重载数据之前的位置。在顶层节点比较多,不展开子节点也有滚动条的场合,重新加载数据,如果指定了 scrollPos: 'fixed' 参数,是可以保持滚动条位置的。
修正方法:
方法1:修改treeTable.js,在treeTable执行reload时先记下重载前的滚动条位置,重载后重新设置滚动条到原来的位置。

  // 重载
  treeTable.reload = function (id, options, deep, type) {
    // deep = deep !== false; // 默认采用深拷贝
    var that = getThisTable(id);
    if (!that) return;
    /**
     * treeTable重载数据时,会先加载显示顶层节点,然后根据重载数据前的子节点展开状态,展开相应的子节点,
     * 那么如果重载数据前有滚动条滚动在某个位子,重新加载时顶层节点如果比较少,只显示顶层节点时没有滚动条的情况下,
     * 自动展开子节点后,滚动条就会显示在顶部,无法保持在重载数据之前的位置。
     */
    if ((that.config.scrollPos === 'fixed' || options.scrollPos === 'fixed') && type === 'reloadData') {
      // 处理保持滚动条的问题,重载数据前记住滚动条的位置
      let scrollTop = $('div[lay-id="' + id + '"]').find('.layui-table-body.layui-table-main').scrollTop();
      if (typeof options.done === 'function' || typeof that.config.done === 'function') {
        let oriDone = options.done || that.config.done;
        options.done = function(){
          oriDone && oriDone.call(this);
          $('div[lay-id="' + id + '"]').find('.layui-table-body').scrollTop(scrollTop);
        }
      }
    }
    that.reload(options, deep, type);
    return thisTreeTable.call(that);
  };

方法2:自己的代码中打个补丁,将就一下

  treeTable.on("toolbar(ID-treeTable-demo)", function (obj) {
    var config = obj.config;
    var tableId = config.id;
    if (obj.event === "reloadData") {
      // 修正treeTable的 scrollPos: 'fixed' 参数无效,重载数据不能保持滚动条位置的问题
      let scrollTop = $('div[lay-id="' + tableId + '"]').find('.layui-table-body.layui-table-main').scrollTop();
      treeTable.reloadData('ID-treeTable-demo', {
        scrollPos: 'fixed',
        done: function() {
          $('div[lay-id="' + tableId + '"]').find('.layui-table-body').scrollTop(scrollTop);
        }
      });
    }
  });

演示地址

from layui.

stackblitz avatar stackblitz commented on June 1, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from layui.

Cuixq123 avatar Cuixq123 commented on June 1, 2024

这个很关键,很需要这个,希望早日发版

from layui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.