Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4017

Grid renders nothing after clear() and addAll()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 8.6.0
    • 8.0.0, 8.5.2, 8.5.1.2
    • None
    • Security Level: Jimmy
    • None
    • None

      Steps to Reproduce
      1. run the attached example
      2. click "doFilter by clear/add"
      3. click "doClear by clear/add"

      Current Result

      no row rendered

      Expected Result

      render first 50 items

      Debug Information

      • if you click column C to sort first, then do step 2, 3, this issue doesn't happen.
      • if you set <custom-attributes org.zkoss.zul.grid.autoSort="ignore.change"/>, this issue doesn't happen.
      • if you call model.sort() before setModel(), this bug doesn't happen. But this can't fulfill user requirement.

      Workaround

      Grid.java

      private static boolean doSort(Grid grid) {
          Columns cols = grid.getColumns();
          if (!grid.isAutosort() || cols == null)
              return false;
          for (Iterator it = cols.getChildren().iterator(); it.hasNext();) {
              final Column hd = (Column) it.next();
              String dir = hd.getSortDirection();
              if (!"natural".equals(dir)) {
                  return hd.doSort("ascending".equals(dir));
                  // TODO ZK#5825: change is here to return real doSort value not just true.
                  // return true;
              }
          }
          return false;
      }
      

      Then, we changed the first case within onListDataChange and introduce an else case if doSort returns false:

      private void onListDataChange(ListDataEvent event) {
          //sort when add
          int type = event.getType();
          if ((type == ListDataEvent.INTERVAL_ADDED || type == ListDataEvent.CONTENTS_CHANGED)
              && !isIgnoreSortWhenChanged()) {
              // TODO ZK#5825: negation case is fixing missing call to render if no column is sorted.
              if (doSort(this)) {
                  getDataLoader().updateModelInfo();
              } else {
                  getDataLoader().doListDataChange(event);
                  postOnInitRender();
              }
          } else {
      

        1. 4017.zul
          1 kB
        2. MyItem.java
          0.2 kB
        3. MyRowRenderer.java
          0.4 kB
        4. sortFirst.png
          sortFirst.png
          7 kB
        5. ZK4017Composer.java
          2 kB

            rudyhuang rudyhuang
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 3 days
                3d
                Remaining:
                Time Spent - 5 hours Remaining Estimate - 2 days, 3 hours
                2d 3h
                Logged:
                Time Spent - 5 hours Remaining Estimate - 2 days, 3 hours
                5h