I am using AngularJS ng-grid and trying to make it 1. Auto-size column width based on the column content 2. When less columns are displayed, to make last column width auto-size to fill the empty area (For example say I have 8 columns each with width : 100 and the whole ng-grid width is 800...then if I hide 4 columns, then last column width should automatically be equal to 500).
So far I have the following code for task 1 above but unfortunately it is not working (columns are not auto-sized based on column content). So I was wondering if anyone can please help by telling me what I am missing here, and how I can do task 2. Thanks
var app = angular.module('myNGridApp', ['ngGrid']);
app.controller('myNGCtrl', function($scope) {
$scope.myData = [{id: "#4", di: 50, taskstatus: "Lorem Ipsum text", notes: "Lorem Ipsum text", datecreated: "02/04/2014"},
{id: "#4", di: 50, taskstatus: "Lorem Ipsum text", notes: "Lorem Ipsum text", datecreated: "02/04/2014"},
{id: "#4", di: 50, taskstatus: "Lorem Ipsum text", notes: "Lorem Ipsum text", datecreated: "02/04/2014"},
{id: "#4", di: 50, taskstatus: "Lorem Ipsum text", notes: "Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text Lorem Ipsum text ", datecreated: "02/04/2014"},
{id: "#4", di: 50, taskstatus: "Lorem Ipsum text", notes: "Lorem Ipsum text", datecreated: "02/04/2014"}];
$scope.columnDefs= [{ field: 'id', displayName: 'ID', resizable: true, minWidth: 100, width: 'auto' },
{ field: 'di', displayName: 'DI', resizable: true, minWidth: 100, width: 'auto' },
{ field: 'taskstatus', displayName: 'Task Status', resizable: true, minWidth: 200, width: 'auto' },
{ field: 'notes', displayName: 'Notes', resizable: true, minWidth: 400, width: 'auto' },
{ field: 'datecreated', displayName: 'Date Created', resizable: true, minWidth: 200, width: 'auto' }];
$scope.gridOptions = {
data: 'myData',
columnDefs: 'columnDefs',
footerVisible: true,
enableColumnResize: true,
filterOptions: {filterText: '', useExternalFilter: false},
showColumnMenu: true,
showFilter: true,
plugins: [new ngGridFlexibleHeightPlugin()],
virtualizationThreshold: 10,
};
});