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

[Solved] Collapse all groups on load

4 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 22 Aug 2011, 11:13 PM
I have an ajax loaded grid that is grouped by a value. When the grid loads, all of the groups are expanded by default. I would like to change this so that all the groups are collapsed by default. I found a solution that someone posted...

function gridCollapse(e) {
    var grid = $('#' + e.target.id);
    $.each(grid.find('td.t-group-cell').parent('tr'), function(index, value) {
            $(value).attr('style', 'display: none;'); 
    });
    $.each(grid.find('.t-icon'), function(index, value) {
            if ($(value).hasClass('t-collapse' )) {
                $(value).removeClass('t-collapse').addClass('t-expand');
            }
    });
}

tied to the OnLoad client-side event, however, this does not seem to work with the latest version of the grid control. Have some of the class names and/or references changed? Is there any possibility you could let me know what the syntax should look like? Thanks so much!

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Aug 2011, 06:33 AM
Hello Philip Senechal,

 Is your grid ajax or server bound? If it is ajax bound it may be empty during the OnLoad event hence the code snippet may not work. If this is the case you can try with the OnDataBound event instead.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Philip Senechal
Top achievements
Rank 1
answered on 23 Aug 2011, 06:15 PM
Hi Atanas,

Thank you for your response...you are absolutely correct. My Grid is ajax bound and changing the event to OnDataBound works.

Question for you...if this is possible...once the grid loads and the groups are collapsed, if I expand a group, edit one of the rows, then submit the changes, the group collapses again since the grid is rebinding and the OnDataBound event fires again. Do you know if it's possible to set this up in such a way that the group I expanded to edit, stays expanded after the update?

Thanks again for your assistance...much appreciated
0
Accepted
Atanas Korchev
Telerik team
answered on 24 Aug 2011, 08:17 AM
Hi Philip Senechal,

 I've created a new code library project which shows how to persist the grid expand state.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Philip Senechal
Top achievements
Rank 1
answered on 24 Aug 2011, 04:53 PM
Thanks Atanas...your solution is brilliant and works perfectly!
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Philip Senechal
Top achievements
Rank 1
Share this question
or