Dynamic Widget

Is it possible to make widget dynamic in size ? If can, how to do it ?
For example, if the grid only consists of 3 data, the widget become smaller. But if the grid consists of 10 data, then the widget become higher.