Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
Expand all with several levels
posted

Hi, 

I want to expand all the rows in my grid, I have this function that works fine with 2 levels grid, but now, I have a 3 levels grid, and it doesnt work , could you help me to figure out a solution ? 

function ExpandAllRowsGrouped(Webgrid) {
var grid = $find(Webgrid);
var rows = grid.get_gridView().get_groupRows()
var oRow
for (i = 0; i < rows.get_length() ; i++) {
oRow = rows.get_row(i);
oRow.set_expanded(true);
}
}

thanks.

Parents
No Data
Reply
  • 8421
    Verified Answer
    posted

    Hello Hugo,

    Could you provide me with a few more details of what you want to do? I see here that you are expanding the group rows. Are you wanting to just expand group rows and child group rows, or do you want to be able to expand every row in the grid? Which approach you want to take will change the solution slightly.

    In general, a group row is going to have two properties that it exposes, get_childGroupRows and get_rows. childGroupRows is going to return all child rows that are also used for grouping and can be expanded like you are doing. get_rows is going to expose an array of child ContainerGridRows which also have the same way of expanding. The difference, however, is that if you want to expand children of a ContainerGridRow then you are going to want to call its get_rowIslands property and iterate over each of the ContainerGrid objects, accessing their rows.

    For this latter approach with iterating over container grids it would look something like the following:

    Code Snippet
    function expandAll() {
        var grid = $find('<%= grid.ClientID %>');

        expandGridRows(grid.get_gridView());
    }

    function expandGridRows(containerGrid) {
        var rows = containerGrid.get_rows(),
            rowLen = rows.get_length();

        for (var i = 0; i < rowLen; i++) {
            var row = rows.get_row(i);
            row.set_expanded(true);

            var childBands = row.get_rowIslands();
            if (childBands.length > 0) {
                for (var j = 0; j < childBands.length; j++) {
                    expandGridRows(childBands[j]);
                }
            }
        }
    }
Children
No Data