Turnoff Scrolling within Angular UI ng-grid?

我的未来我决定 提交于 2019-11-30 05:04:01
Dharmesh

I recently ran into same issues and found a solution at https://groups.google.com/forum/#!topic/angular/KiBXP3eKCDY

You want ng-grid to initialize after you have data.

The following solution requires using angular-ui:

<div ui-if="dataForGrid.length>0" ng-grid="gridOptions" ng-style="getTableStyle()"  />

$scope.getTableStyle= function() {
   var rowHeight=30;
   var headerHeight=45;
   return {
      height: ($scope.dataForGrid.length * rowHeight + headerHeight) + "px"
   };
};

Adding this to your CSS will fix your problem:

.ngViewport{
    height:auto !important;
}
.ngCanvas, .ngViewport, .ngRow, .ngFooterPanel, .ngTopPanel   {
   width: 100% !important;
}
.ngRow {
   border-bottom:none !important;
}

In your CSS, you can try overriding the height of the div containing the rows, so the rows don't overflow the container:

.ngViewport {
  height: auto !important;
}

You can also fill in the white space that ng-grid leaves for the scrollbar with the row background colour (although unfortunately the data last cell won't expand to fill the gap):

.ngCanvas {
   width: 100% !important;
}
.ngRow {
   width: 100% !important;
}

Depending on your table layout you might need to change some other styles too, but these are the main ones. Also take care not to set a height for the entire ngGrid.

yes there is a plugin which offers such facility its ng-grid-flexible-height.js

you can see the plunker for how its used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!