Remember Detail Rows after Grid Read

3 posts, 1 answers
  1. Brian
    Brian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 27 Mar 2018 Link to this post

    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. Answer
    Stefan
    Admin
    Stefan avatar
    2913 posts

    Posted 29 Mar 2018 Link to this post

    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.
  3. Brian
    Brian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 05 Apr 2018 in reply to Stefan Link to this post

    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 + "']"));
                }
            });
        });
    }
Back to Top