Star Sizing

This sample shows how you can use XAML-style star sizing to implement flexible layouts with the FlexGrid. Star sizing is specified in the width property of the Column object.

Star sizing is similar to percentage sizing, except that the values do not have to add up to one hundred. A width of '3*' means 'three times wider than 1*.' The total size used to calculate the layout is the current width of the control minus the width of any non-star columns divided by the number of stars specified.

You can use star-sizing to implement grids where the last column expands to fill all of the available space. To do this, simply set the width of the last colunm to *. You might also want to set the minWidth property of the last column to prevent it from getting too narrow.

Note that the minWidth and maxWidth properties of columns also affect the layout calculations. You can resize the entire grid in each sample by resizing the window.

These samples use the WjFlexGrid and WjFlexGridColumn components and Angular 2.

Example 1:

This grid has four columns. The first is 80 pixels wide and can be resized between 40 and 160 pixels. The other three have widths of 2*, *, and *, and cannot be resized using the mouse.

Notice that the second column is twice as wide as the third and fourth columns, and that they keep these proportions even as you resize the first column or the whole grid.



Example 2:

This grid shows how you can make any column stretch to fill the available space. In this case, we set the width of the second column to * to achieve that effect.

We also set the minimum width of the second column to 100 pixels in order to prevent it from getting too narrow when the other columns in the grid are resized, and we prevent users from resizing this column with the mouse.



Example 3:

This example sets all widths to *, which means the space available is divided equally among them. Resize the browser and notice how the grid resizes and the columns fill it up equally.

Also, unlike the other examples, this one sets the allowResizing property of the entire grid rather than an individual column. We set this one to None, but you may also choose Columns, Rows, or Both.