This is a migrated thread and some comments may be shown as answers.

Remember Detail Rows after Grid Read

2 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 27 Mar 2018, 02:31 PM

Hi,

I am having an issue trying to update the parent in a hierarchical grid after making changes in the child.
I am remembering which detail rows have been opened at the time they are opened using the DetailExpand event
I can get the data-uid's of all parent rows without issue.

So then when I update a child I need to refresh the child and also refresh the parent so that some counts are updated.
After the child is updated I call Read on the parent

$('#grid').data().kendoGrid.dataSource.read()


This also works as expected and the parent grid reloads its data with the new counts.
However I then want to re-open detail grids that were open before read was called so the user is back where they were, not be in the default situation that all rows are collapsed again.

I thought I could just call expandRow on the grid for the id(s) that I collected earlier

dataGrid.expandRow(dataGrid.tbody.find("tr[data-uid='" + id + "']"))

 

However the data-uid's for all of the parent rows have now changed making my collection useless.
I thought a slightly more noddy way to do it would be to remember the indexes of the rows that were open but this is no good as the rows can change order upon the data re-loading, those counts that are being updated are used in sorting, so that is no good.

Is there something I can do to keep the data-uid's consistent across calls or some other way of remembering which ones are expanded?

By the way I also tried:

$('#grid').data().kendoGrid.refresh()

 

This allows me to open up the rows that were expanded but it doesn't actually reload the data so the parent counts are not updated...

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 29 Mar 2018, 06:35 AM
Hello, Brian,

Thank you for the details.

Indeed, when the Grid is refreshed with read the uids will be changed. In this case, I can recommend using the dataItem id as it is unique and even if the row positions is changed its ID will still be same.

I made an example demonstrating this and attached it.

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brian
Top achievements
Rank 1
answered on 05 Apr 2018, 03:29 PM

Hi, thanks,

I actually got this working with a bit of jquery:

function onMainGridDataBound() {
    var dataGrid = $('#Grid').data('kendoGrid');
    var dataItems = dataGrid.dataSource.view();
    $.each(expandedRowIds, function (k, v) {
        $.each(dataItems, function (x, y) {
            if (v === y.id) {
                dataGrid.expandRow(dataGrid.tbody.find("tr[data-uid='" + y.uid + "']"));
            }
        });
    });
}
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Brian
Top achievements
Rank 1
Share this question
or