how to persistent expand of row?

When the screen was first loaded, the "enableCollapseAll" property was used to render the grid in full shrink state.

The problem is that every time the data in the grid is updated, all rows collapse, including the rows that were expanded.

how to persistent expand of row?


1 Reply

SM Shek Mohammed Asiq Abdul Jabbar Syncfusion Team June 23, 2023 08:04 AM UTC

Hi Hamim Jeon,


Greetings from Syncfusion support.


Query #:- How to persist expanded state after edited?


To maintain expanded state after performing CRUD actions, you can manually expand the row by using expandByKey method in actionComplete event in Syncfusion treegrid once it updated the values. In the expanded event, we have collected the expanded record based on PrimaryKey values and expand the same record using expandByKey method after performing the action.


Please refer to the following code snippet :

function expanded(args) {

    if (args.data && !isNullOrUndefined(args.row)) {

      primaryKeyList.push(args.data.taskID); //Here we collect the expanded record primary key value

    }

  }

  function actionComplete(args) {

    if (args.type === 'save') {

      treegridObj.refresh();

      // to main the state based on the primary key

      if (primaryKeyList.length > 0) {

        var task = primaryKeyList;

        setTimeout(() => {

          for (var i = 0i < task.lengthi++) {

            console.log(task[i]);

            treegridObj.expandByKey(task[i]); //collapsing row using collapseByKey method

          }

        }, 100);

      }

      this.primaryKeyList = [];

    }

  }

 


Please refer to the following sample : https://stackblitz.com/edit/react-c1eeyg-cubcwf?file=index.html,index.js


Please refer to the following API :

Expanded : https://ej2.syncfusion.com/react/documentation/api/treegrid/#expanded

Action complete : https://ej2.syncfusion.com/react/documentation/api/treegrid/#actioncomplete


KB link for more reference:- https://support.syncfusion.com/kb/article/11977/how-to-maintain-expand-collapsed-state-of-rows-during-page-refresh-in-javascript-treegrid


In case you are using RemoteData, we suggest to refer the below KB:-

https://support.syncfusion.com/kb/article/11200/how-to-maintain-collapsed-state-while-performing-rowdd-with-remote-data


If the above solution doesn’t meet your requirement, share details such as Complete TreeGrid code example, Screenshot/Video demo, Type of dataSource you have used to proceed further.


Regards,

Shek Mohammed Asiq


Loader.
Up arrow icon