- Home
- Forum
- React - EJ 2
- When sorting , row gets collapsed automically.
When sorting , row gets collapsed automically.
- I have used group by and expanded a row of selection and when performing sorting, filtering, adding new column on .the expanded records gets collapsed. I need to make that page stay in the same format when performing sorting and oteh operations.
Hi Viji Palanisamy,
We understand your concern about expanded rows being automatically collapsed after performing the sorting action. Want to prevent the collapse in the first place. The behavior you described is indeed the default functionality of the hierarchy grid. When we performed sorting, filtering, and other actions in grid, resulting in changes to the underlying data source, the grid undergoes a re-rendering process. During this process, any previously expanded rows are collapsed as part of the default behavior.
If you require further assistance, please do not hesitate to contact us. We are always here to help you.
Regards,
Vikram S
Hi Vikram S,
We understand your concern about expanded rows being automatically collapsed after performing the sorting action. Want to prevent the collapse in the first place. The behavior you described is indeed the default functionality of the hierarchy grid. When we performed sorting, filtering, and other actions in grid, resulting in changes to the underlying data source, the grid undergoes a re-rendering process. During this process, any previously expanded rows are collapsed as part of the default behavior.
Can this feature be added by you in any later versions. Please let me know, so it would be easy for us to make some decision. As we feel, that feature is important to us for interpreting some data.
Thanks.
Hi Viji Palanisamy,
We understand that you want to add this feature request from our side. Currently, after performing a filter or any other action, we could not maintain the expand state. Therefore, it is not feasible to add this request.
However, if we were to achieve this requirement at the sample level, there may be some flickering. If this is acceptable to you, we will check the feasibility of meeting your requirement at the sample level.
Regards,
Vikram S
Hi Vikram,
Yes sure. You can work on it to provide solution on how it will look. Can you provide me a sample project for this scenario.
Hi Viji Palanisamy,
Based on your query, you want to maintain the expanded rows after sorting. We have achieved your requirement at the sample level. Please refer to the below code snippet for more reference:
|
Index.js let gridInstance; let expandedIndexes = []; const detailDataBound=(args)=>{ const rowElement = args.detailElement.parentElement.previousSibling; const rowIndex = rowElement.getAttribute('data-rowindex'); expandedIndexes.push(rowIndex); }
|
In this detailDataBound event, it triggers after the detail row is expanded. This event triggers initially upon expansion. We can retrieve the expanded row index in this event and store it in one global variable.
|
Index.js
const load=()=>{ var grid=document.getElementsByClassName('e-grid')[0].ej2_instances[0] grid.on('detail-state-change', (args) => { if (args.isExpanded) { const rowElement = args.detailElement.parentElement; const rowIndex = rowElement.getAttribute('data-rowindex'); if (!expandedIndexes.includes(rowIndex)) { expandedIndexes.push(rowIndex);
} } else{ const rowElement = args.detailElement.parentElement; const rowIndex = rowElement.getAttribute('data-rowindex'); const indexToRemove = expandedIndexes.indexOf(rowIndex); if (indexToRemove !== -1) { expandedIndexes.splice(indexToRemove, 1); } } }); } |
Currently, we don't have any event for expanding and collapsing the child grid. Therefore, we use the internal event of "detail-state-change" in the grid.on() function and check whether it is in the expanded state using the isExpanded property. Then, we retrieve the row indexes and store them in the expandedIndexes variable.
|
Index.js const actionComplete = (args) => { if (args.requestType === 'sorting') { expandedIndexes.forEach(index => { gridInstance.detailRowModule.expand(parseInt(index)); }); } }; |
When sorting, we expand the records based on their index using the expand method in the actionComplete event. Please refer to the below sample for more reference:
Sample: https://stackblitz.com/edit/react-h4777q-vhwkiz?file=index.js
actionComplete: https://ej2.syncfusion.com/react/documentation/api/grid/#actioncomplete
Load: https://ej2.syncfusion.com/react/documentation/api/grid/#load
detailDataBound: https://ej2.syncfusion.com/react/documentation/api/grid/#detaildatabound
Please let us know if you have any further queries.
Regards,
Vikram S
Thanks for the update Vikram.
Just for some clarification, The event triggers initially upon expansion. We can retrieve the expanded row index in this event and store it in one global variable. If we sort it based on Employee ID, then index will be pointing to wrong aggregate after sorting. So can you clarify this to me. Even after sorting, can it poin to correct index.
Consider we have 10 index. If we expand index 1 and we sort based on employee id. Then it needs to points to that particular data it was expanding rather than pointing to index. Can this feature be applicable for you to do or is it possible to make expand row based other feature not by indexing.
Hi Viji Palanisamy,
After reviewing your query regarding “sorting based on Employee ID resulting in the index pointing to the wrong aggregate”, we are unsure of the specific action you are taking with the sample.
Additionally, in the statement, “Consider we have 10 index. If we expand index 1 and we sort based on employee id. Then it needs to points to that particular data it was expanding rather than pointing to index. “ – please clarify what you mean to point and what needs to be pointed after sorting.
Please provide a detailed explanation of the issue you are experiencing with the sample and consider including a video demonstration to assist us in further validating the problem.
Regards
Aishwarya R
Additionally, in the statement, “Consider we have 10 index. If we expand index 1 and we sort based on employee id. Then it needs to points to that particular data it was expanding rather than pointing to index. “ – please clarify what you mean to point and what needs to be pointed after sorting.
Note for Clarification:
Consider we have 10 index. If we expand index 1 and we have 5 employee id in it. we sort based on employee id. These grouping will be pushed to last as it has biggest employee id. Then for example the grouping which was in the last index will be brought somewhere in middle or at first based on value. Now the expanded grouping should not point to first group by. It should point to the last one as that has biggest value.
Now it should expand 1 Nancy, rather it expands the Anne d
Hi Viji Palanisamy,
Thank you for providing the details.
We have achieved your requirement of showing the expanded records of the rows even after it has been sorted by using the getRowIndexByPrimaryKey method. The Grid must contain a column with the property isPrimaryKey enabled to use this method. In the below sample, the 'EmployeeID' column is a primary key column. The expandedIndexes contain the primary key value of the expanded rows. After sorting, the expanded row is identified with the primary key values, and it has been expanded. Please refer to the below sample and code example for more information.
|
Index.js
const detailDataBound = (args) => { const rowElement = args.detailElement.parentElement.previousSibling; const rowIndex = rowElement.getAttribute('data-rowindex'); // Getting the primary key values var record = gridInstance.getCurrentViewRecords()[parseInt(rowIndex)]; var primaryKeyValue = record['EmployeeID']; expandedIndexes.push(primaryKeyValue); }; const actionComplete = (args) => { if (args.requestType === 'sorting') { expandedIndexes.forEach((index) => { // Getting the row index based on primary key values var rowIndex = gridInstance.getRowIndexByPrimaryKey(index) gridInstance.detailRowModule.expand(rowIndex); }); } };
|
Sample: https://stackblitz.com/edit/react-h4777q-zbvqoi?file=index.js,data.js
If you need any further assistance or have additional questions, please feel free to let us know.
Regards
Aishwarya R
- 9 Replies
- 3 Participants
-
VP Viji Palanisamy
- Feb 29, 2024 06:01 AM UTC
- Mar 20, 2024 03:45 AM UTC