React Grid Sizing

    The Ignite UI for React Sizing feature in React Grid is an important aspect of creating responsive and user-friendly grid interfaces. The React Grid Sizing feature enables users to adjust the width and height of the grid to accommodate different screen sizes, content, or user preferences. In terms of border and padding size for the IgrGrid, they are taken into its width/height size calculations or also known as Border box sizing. It is applied in all scenarios.

    [!Note] If the Border box sizing is overridden by the user we cannot guarantee that the IgrGrid will size correctly.

    React Grid Width

    If the width input does not have value assigned, its default value is 100% and the IgrGrid tries to fill the available space. You can check how the grid reacts to it in the Percentages section.

    [!Note] Setting manually the width style of the IgrGrid itself will result in an unexpected behavior.

    Null

    The grid's width can accepts value of null, which when set, renders all columns in the DOM. The grid sizes accordingly so there is no grid horizontal scrollbar since column virtualization is not applied.

    • If there are 6 columns and none of them has width defined, the grid will have width of 816px, because each column by default have assigned width of 136px in this scenario. Same will happen if the columns have width in percentages. If vertical scrollbar is rendered or there are features that render additional columns their width will be added also.
    • Se houver 6 colunas com a largura da coluna definida, 200px elas caberão em nossa janela e todas ficarão visíveis:
    • Se houver mais colunas ou com largura maior que saem da visualização do navegador, todas elas ainda serão renderizadas. Vamos ter a mesma quantidade de colunas, mas cada uma com largura de coluna de 300px. Como nem todos cabem na área de visualização do navegador, ele criará uma barra de rolagem nativamente. O próximo exemplo exibe este cenário exato:
    • Se a grade tiver um elemento pai de qualquer tipo e não tiver nenhum estouro definido, ela ainda renderizará todas as colunas visíveis. Caso contrário, se o elemento pai tiver estouro auto ou scroll, uma barra de rolagem para esse elemento pai será renderizada nativamente. O pai tem uma altura maior para facilitar a visualização no exemplo a seguir.

    [!Note] Due to this behavior, if the grid data contains too many columns, it might have significant impact on the browser performance, since all columns would be rendered without virtualization.

    Pixels

    When the IgrGrid has its width input is set to pixels it will set the whole grid size to that value and it will be static. It will not react to any browser resizing or changes in the DOM, although this is not the case for the grid content:

    • When width is set in pixels in order for the grid to render horizontal scrollbar, its content width needs to exceed the specified grid width. Let's, for example, have the combined width of the columns exceed 1200px. In this case a horizontal scrollbar will be rendered.
    • For scenarios where the grid has a parent element, it depends on the parent styling if it will render scrollbar or not. Everything else related to the grid itself is still retained. If the parent element width is smaller than the grid's width and has overflow style set to auto or scroll, it will render scrollbar natively. For example, if the parent has width set to 1000px and the IgrGrid width is still 1200px, it will look similar to the following illustrations:

    Percentages

    When the width of the IgrGrid is set to percentages it will size the grid according to the parent element's width. If the parent element does not have width specified the IgrGrid will size relative to the browser window.

    • For example, if we set the grid width input to 100% and there is no parent element it will fill 100% of the available width of the browser window. If it is resized the grid will resize as well accordingly.
    • Se definirmos a largura da grade como 100% e houver um elemento pai com largura específica de, isso significará que a grade será dimensionada 1200px em relação a esse elemento e sua largura final será 1200px.
    • If we have a parent element with width of 1000px and have the grid's width set to 150%, the calculated grid width will be 1500px. In this case the grid will still render fully visible but if we set overflow: auto of the parent, that parent will render scrollbar on its own.

    React Grid Height

    By default if no height is defined for the IgrGrid, it will be set to 100%. You can check how the grid reacts depending on the DOM structure in the Percentages section.

    [!Note] Setting manually the height style of the IgrGrid itself will result in an unexpected behavior.

    Null

    The IgrGrid height input can accept null value, which when set, displays all rows with no scrollbar no matter how many they are. In this case, there is no vertical virtualization since the grid renders all rows anyway.

    • Se tivermos dados com 14 linhas, neste caso, a grade renderizará todas as 14 e dimensionará a grade para que todas fiquem visíveis sem nenhum espaço vazio dentro da grade.
    • Se tivermos 24 linhas, a grade ainda renderizará todas as linhas, mas como são muitas, elas excedem os limites do navegador. É por isso que o próprio navegador renderizará a barra de rolagem vertical por padrão para que o usuário possa rolar para baixo até o restante das linhas.
    • If there is a parent element with defined height, the grid will still render all rows and not be affected. Let's say the parent has height of 650px. If it has overflow set to auto or scroll, it will render a vertical scrollbar but the grid will still be unaffected:

    [!Note] Due to this behavior, if the grid data contains too many rows, it might have significant impact on the browser performance, since all rows would be rendered without virtualization.

    Pixels

    Setting the IgrGrid height in pixels is more straightforward since the grid will size to that specific size in all occasions similarly to how width is set in pixels.

    • Se definirmos, por exemplo, a altura 500px com 4 linhas para nossos dados, a grade ficará nesse tamanho e, como 4 linhas não são suficientes para preencher a área visível, espera-se que tenha alguma área vazia.
    • If the number of rows exceeds the visible area of the grid when height is set to pixels a vertical scrollbar will be rendered. For example, a grid with 500px height set and 14 rows will be rendered the following way:
    • If there is a parent element with height defined, unless it has overflow set to auto or scroll, the grid will still be fully visible. Otherwise it will render a scrollbar.

    Percentages

    When the height input is set to percentages, the IgrGrid will size based on the parent element height. If the parent element has its height set in pixels or percentages, the grid will size relative to the size of the parent.

    Quando o elemento pai não tem altura definida, o navegador não atribui altura a ele inicialmente e o dimensiona com base em seus filhos e seu tamanho. É por isso que não há como a grade saber qual altura de base usar para aplicar o dimensionamento percentual com base nela. Por esse motivo, ele renderizará no máximo 10 linhas e, se forem mais linhas, uma barra de rolagem vertical será renderizada. Caso contrário, a grade se ajustará ao número de linhas renderizadas. Examinaremos esse cenário com mais detalhes nos próximos exemplos.

    Let's have width set to 1200px and the parent element not having any size applied to it:

    • Se houver menos de 10 linhas, a grade tentará encaixar todas as linhas na área visível sem ter um espaço vazio entre a última linha e a parte inferior da área visível. Por exemplo, vamos ter os dados da grade consistindo em 7 linhas. A grade renderizará todas as 7 linhas sem barra de rolagem vertical e sem espaço vazio dentro da grade.
    • Se houver mais de 10 linhas, uma barra de rolagem vertical será renderizada para o restante das linhas e apenas 10 linhas poderão ser visíveis a qualquer momento. No próximo exemplo, apenas o número da linha é aumentado para 14.
    • If we set the parent element height to 800px and the IgrGrid to 100% height this means that the grid will be sized to 100 percentages of 800px.
    • If the IgrGrid height is set to a number bigger than 100% and the parent element has height, for the parent to render scrollbar it again needs to have overflow set to auto or scroll. Otherwise the grid will be fully visibly and size relative to the parent size.
    • Se quisermos que a grade seja dimensionada para 100% a partir da janela do navegador, precisaríamos definir as body alturas dos elementos da grade pai para 100%. Nesse caso, o elemento pai pode ser dimensionado e a grade será dimensionada de acordo se o navegador for redimensionado.

    React Grid Column Sizing

    Dependendo do tamanho da grade em si, as colunas dentro dela também podem ser dimensionadas de forma diferente, o que pode resultar em cenários em que a grade renderiza a barra de rolagem horizontal ou não. As colunas podem ter largura definida em pixels, porcentagens ou dimensionadas automaticamente quando nada é definido. Vamos dar uma olhada mais profunda nesses cenários nesta seção.

    Default

    Por padrão, quando uma coluna não tem uma largura especificada, ela tentará dimensionar automaticamente, para que seja preenchida se houver algum espaço vazio disponível na área de exibição em grade. As colunas dimensionadas automaticamente têm largura mínima de 136px, portanto, se a área disponível for menor do que 136px para essa coluna, o padrão será esse tamanho.

    Quando a grade é redimensionada nesses cenários, a largura da coluna também é atualizada para refletir as alterações, para preencher qualquer novo espaço vazio disponível.

    • If a column does not have specified width and the IgrGrid has width set to null, it will be sized to the minimum of 136px. This means that for a grid with width null and 6 columns that don't have width, each column will be sized to 136px.
    • Quando houver várias colunas dimensionadas automaticamente, elas dividirão o espaço disponível entre si igualmente. Isso significa que, se tivermos 6 colunas e houver uma área vazia, cada uma será dimensionada 1200px para 200px.
    • If there is available empty space, so that each autosized column will be less than 136px, all autosized columns will default to 136px and the grid will render horizontal scrollbar. In the next example let's have 12 autosized columns and the grid width set to 1000px.
    • If a column does not have width specified, but all other columns have either width in pixels or percentages, that column will try to also fill the available space. For example, if we don't have width set to the first column and all other 5 have width of 100px, the first will fill the rest.
    • Same applies if multiple columns does not have width specified, all will divide the available space between each other equally. In the next illustration the first column has width set to 100px.

    [!Note] Feature columns like Row Selector checkbox column and etc. fill additional space that is taken into account when autosizing columns.

    Pixels

    When columns have set specific width in pixels, they stick to that size, unless they are resized manually. Since the combined width of the columns is static, it can be less than the IgrGrid width or exceed it.

    • If the combined width of all columns is less than the IgrGrid width, there would be an empty are inside the grid that the columns wouldn't be able to fill. This is the expected behavior of the IgrGrid. In the next example the columns have 150px width.
    • If the combined width of all columns is bigger than the actual IgrGrid width, a horizontal scrollbar will be rendered. In the next example each of the 6 columns have width of 300px and grid has width of 1200px, which means that the columns combined have excess of 600px that goes out of bounds.

    Percentages

    When columns have set width in percentages, their size is calculated relatively to the grid size. It is similar to how width in pixels works, but provides also responsiveness to the columns which means that when the grid is resized, the columns also will resize accordingly.

    • Se a largura combinada de todas as colunas for menor que 100%, da mesma forma que em pixels, pode haver uma área vazia da grade que as colunas não cobrem.
    • Se a largura combinada for exata, 100% as colunas preencherão todo o espaço disponível da grade.
    • Se a largura combinada exceder 100% para que o usuário possa ver as colunas fora da exibição, uma barra de rolagem horizontal será renderizada.
    • If columns are set in percentages and the grid width is set to null, it would apply width of 136px to each column. That is because the columns cannot be sized relatively to the grid, since it doesn't have width itself and relies on its content to be sized when its width is null. In the following example all 6 columns have width set to 50%:

    API References

    Additional Resources

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.