Set child row selection of FlexGrid with childItemsPath

Posted by: stefan.brenner.a on 7 February 2019, 9:44 pm EST

    • Post Options:
    • Link

    Posted 7 February 2019, 9:44 pm EST

    Hello,

    I have a grid with a tree of multiple levels using the childItemsPath. This grid allows selecting rows and my UI reacts on it. This works fine on all levels. Now I need to go the opposite direction and let the grid react to a change in my UI by setting its selected row.

    I’m trying to set this selection by setting the currentItem of the the grid. This works fine if the node to be selected is at the top level of the tree, but if I want to select an item on a lower level it will not work.

    Can you please help me figure out how to do this? I thought about using the rows collection of the grid but since I have many rows the row to be selected probably hasn’t been rendered yet. So how else could I set a child row as selected and then scroll it into view?

    Thanks and best regars,

    Stefan

  • Posted 10 February 2019, 4:37 pm EST

    Hi,

    For child rows, we may use the select method to select the row and scroll it into view.

    Please refer to the following code snippet and sample demonstrating the same:

    selectRow(grid, rowIndex){    
        let rowIndex = 15;
    
        // make sure row is visible
        for (var i = rowIndex; i >= 0; i--){
          let tempRow = grid.rows[i];
          let rng = tempRow.getCellRange();
          // if in range
          if(rng.containsRow(rowIndex)){
            // expand parent row 
            tempRow.isCollapsed = false;
          }
          if(tempRow.level == 0){
            // reached top level, no need to look any further
            break;
          }
        }
        grid.select(new wjcGrid.CellRange(rowIndex, 0, rowIndex, grid.columns.length - 1), true);
      }
    

    https://stackblitz.com/edit/angular-7so2dp?file=src%2Fapp%2Fapp.component.ts

    ~Sharad

  • Posted 17 February 2019, 11:16 pm EST

    Hi,

    works nicely,

    Thanks and best regards,

    Stefan

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels