We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Tree View - On expand/collapse row before data bound with virtualzation makes rows dissapear

Hi!

I have a tree grid that updates all the row when the user makes an edit. The dataSource is local but recreates all the rows on edit.
I tried to mantain the expand/collapsed states of the rows so when the user edit and the grid refresh he doesn't lose the state of the grid on wich he was viewing.
I have virtualization enabled and when I tried to add the expand or collapse state in the beforeDataBound (because I want that the rows draw in the expandend/collapsed state) some of the rows dissappear, but when I scroll they are re drawn.

If I disable virtualization it works correctly. I have wrote another ticket with virtualization problems, maybe it's related, but I want to know wich is the way to maintan the expand/colapsed state when all the rows are refreshed. I created and object with the rows ids that are collapsed/expanded and in beforeDataBound I set the row['expand`] depending on that state. Maybe there is a better way to do this.

Here is the code, and I attached a video to show the error:
handleDataBound(args) {
console.log("Data Bound", args);
const rows = args.result;
if (this.updateCollapse) {
this.updateCollapse = false;

if (this.rowStates) {
console.log("UPDATE COLLAPSE", this.rowStates);
Object.keys(this.rowStates).forEach(
rowId => {
if (rows) {
const row = rows.find(gridRow => gridRow.id === rowId)
const state = this.rowStates[rowId];
if (row && state) {
row['expanded'] = state === RowCollapsedState.Expanded;
}
}
}
)
}
}
onCollapsed(args) {
if (args.data && args.data.id) {
const rowId = args.data.id;
this.rowStates[rowId] = RowCollapsedState.Collapsed
// this.addCollapsedRow.emit(rowId);
}
}

onExpanded(args) {
if (args.data && args.data.id) {
const rowId = args.data.id;
this.rowStates[rowId] = RowCollapsedState.Expanded
// this.addCollapsedRow.emit(rowId);
}
}



Attachment: SVM_Angular__Google_Chrome_01_09_2020_09_57_18_8a89209e.7z

3 Replies 1 reply marked as answer

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team September 2, 2020 04:02 PM UTC

Hi Cesar, 

Thanks for contacting Syncfusion Support. 
 
Query#:- I tried to mantain the expand/collapsed states of the rows so when the user edit and the grid refresh he doesn't lose the state of the grid on which he was viewing. 

We have checked your query and prepared sample with Virtualization and Editing enabled but we are unable to reproduce the problem at our end. State remain persist after performing Edit action(for both Enable/Disable Virtualization) 


So we need some more additional details to find the cause of the issue. Share us the following details. 

  1. Share how you have maintained the state while disabling Virtualization.
  2. If possible replicate the issue in the above sample and revert us back.
  3. Product version details.
  4. Share us the details about how you are updating the new set of rows on Editing.
  5. If possible share us the Video Demo(with and without Virtualization)

Regards, 
Farveen sulthana T 
 



CS Cesar Smerling September 7, 2020 02:37 PM UTC

Hello! I cannot download the sample beacuse of security of my company.

What I need is to mantain the state of collapsed/expanded rows when the rows updated (all the dataSource is reloaded on any edit in my case, the array is build again). What I have to identify the row expanded/collapsed state is the id.

I want to know if there is a way to set that state of the row (searched by id) before the data is draw in the grid.

Thanks


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team September 8, 2020 02:40 PM UTC

Hi Cesar, 
 
Query#:- I want to know if there is a way to set that state of the row (searched by id) before the data is draw in the grid. 

From your query we clearly understood that you want to maintain Expand/Collapse state on updating certain set of rows again. We have achieved this requirement with slight modification from your provided code example. In the collapsed event of the TreeGrid we have get the state of the Row(whether Collapsed or not) and based on that we have updated the new set of rows with that State in beforeDataBound event. 

Refer to the code below:- 

App.Component.html 
<ejs-treegrid [dataSource]="treeRows" idMapping="id" parentIdMapping="pid" #treeGrid 
    [enableVirtualization]="true" [height]="600(beforeDataBound)="dataBound($event)" 
       (expanded)="onExpanded($event)" (collapsed)="onCollapsed($event)"> 
  <e-columns> 
    <e-column field="label" ></e-column> 
          .    .    . 
  </e-columns> 
</ejs-treegrid> 
 
App.Component.ts 
export class AppTreeGridComponent implements OnInit, AfterViewInit { 
  @ViewChild('treeGrid') public grid: TreeGridComponent; 
  public state: boolean; 
  constructor(private rowsService: RowsService) { } 
 
  ngOnInit() : void { 
     
 
  } 
    
 
onExpanded(args) 
{ 
   .    .    . 
} 
onCollapsed(args) 
{ 
    const rowId = args.data.id; 
    this.state = !args.data.expanded;   
    this.rowStates[rowId] = this.state; 
} 
 
dataBound(args: any) 
{ 
    const rows = args.result; 
    if (this.rowStates) 
    { 
        console.log("UPDATE COLLAPSE", this.rowStates); 
        Object.keys(this.rowStates).forEach( 
            rowId => { 
                if (rows) 
                { 
                    const row = rows.find(gridRow => gridRow.id === rowId) 
                    const state = this.rowStates[rowId]; 
                    if (row && state) 
                    { 
                        row['expanded'] = state === false 
 
                    } 
                } 
            }) 
        } 
    } 
} 


Please get back to us if you are facing any difficulties on this. 

Regards, 
Farveen sulthana T 
 


Marked as answer
Loader.
Up arrow icon