Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1415
Igx Hierarchical grid expand of child grid shows incorrect data
posted

Hi team,

I am using Infragistics version 9.1.28 and will update in upcoming month but this is requirement i have to deliver.

Issue: Using Hierarchical Grid load on demand feature. We are expanding first child row by default, the first child row has no data.

When i expand the second child row, it call the api and data is displayed. But the issue is when i hover on first child expand icon it displays second row child data.

Is there any feature where if i expand the second child row than first child collapses and everytime i click on the expand/collapse icon, the OnGridCreated() event is triggered?

TS: 



Please note as this is an ongoing project so please reply ASAP.

Parents Reply
  • 460
    Offline posted in reply to Shobhana Suara

    Hello,

    I have been looking into your question and onRowToggle event didn't help you because you have unique IDs for each row what you can do in this case to implement your requirement when you expand the second row then the first one which is by default expanded to collapse is to use the getRowByIndex method. When the row's toggle event is fired, you'll access the second row with this method, and so you can access its id with rowID property I think in your version 9.1.28. So, you will then check if the event is onRowToggle whether the event is executed for the given second row, that is, whether the second row is toggled and whether it is expanded as explained in the previous answer with the expanded property. If the check is executed, you can similarly take the rowID of the first row with the getRowByIndex method and collapse it afterwards with the collapseRow method.

    public rowToggle(event){
            let secondRowID = this.hGrid.getRowByIndex(2).data.ID;
            if(event.rowID === secondRowID && event.expanded === true){
                let firstRowID = this.hGrid.getRowByIndex(0).data.ID;
                this.hGrid.collapseRow(firstRowID);
            }
        }

    Currently, the igx-hierarchical grid does not offer an event to be triggered when the mouse enters or leaves the igx-icon element of the rows, but still this requirement of yours can be achieved with two possible approaches.

    The first approach is using the ng-template with the igxRowCollapsedIndicator and igxRowExpandedIndicator directives that I mentioned in my previous answer. On the icon that you will place in the ng template, as a click event, you can also put a mouseenter event that is triggered when the mouse hovers over the given icon. After that you can execute your custom function to check if you have hovered over the icon of the first row by passing the row to the function and with it you will access the index, if it is 0 then you have hovered over this first icon.

    <ng-template igxRowCollapsedIndicator let-row>
          <igx-icon (mouseenter)="mouseEnterFunction(row)" (click)="yourFunction(row)">keyboard_arrow_right</igx-icon>
        </ng-template>
    
        <ng-template igxRowExpandedIndicator let-row>
          <igx-icon (mouseenter)="mouseEnterFunction(row)" (click)="yourFunction(row)">keyboard_arrow_down</igx-icon>
        </ng-template>

    public mouseEnterFunction(row){
            if(row.index === 0){
                //your code here
            }
        }

    The next approach is entirely with JavaScript, handling the ngAfterViewInit hook and getting the elements with class .igx-icon with the getElementsByClassName method. Then one can check what is the index of the first icon on the first row in the returned array and get that icon as the HTMLElement. After that after load in setTimeout function, an event listener addEventListener for the mouseenter event can be put on it and a given code can be executed only when hovering over it.

    let icons = document.getElementsByClassName('igx-icon');
    let firstRowIcon = icons[2] as HTMLElement;
    
            setTimeout(() => {
                firstRowIcon.addEventListener('mouseenter', (event) => {
                    //your code here
                 });
            }, 500);

    The described scenario could be observed here:

     

    In addition, I have prepared small sample illustrating this behavior which could be found here. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve, please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated, please feel free to provide your own sample.

    Thank you for your cooperation.

    Regards,

    Georgi Anastasov

    Entry Level Software Developer

    Infragistics

Children