如何根据内容更改Dojo DataGrid的高度

时间:2013-08-16 15:33:55

标签: datagrid height dojo

据我所知,为了让网格显示父div需要一个特定的高度。现在我希望网格根据行数缩小或增长。

1 个答案:

答案 0 :(得分:1)

以下内容将为网格提供300px的最大高度,但如果只显示几行,则会缩小网格。

父div

var divGrid = domConstruct.toDom("<div id='divGrid' style='height:300px;'></div>");
domConstruct.place(divGrid, dojo.byId('Contents'));

创建网格

var grid = new DataGrid({
   id: 'grid',
   store: store,
   structure: layout,
   style: "height:300px",
   loadingMessage: "Loading...",
   noDataMessage: "No data...",
   selectionMode: 'single',
   rowSelector: '20px'
});
grid.placeAt(divGrid);
grid.startup();

现在加载网格后

dojo.connect(grid, '_onFetchComplete', function() {
   var list = query('#grid .dojoxGridContent');
   var height = list[0].offsetHeight + 25;  // additional 25 to account for headers
   if (height < 300) {
      dojo.byId("divGrid").style.height = height + 'px';
      dojo.byId("grid").style.height = height + 'px';
      grid.resize();
      grid.update();
   }
});