|
export class AppComponent {
@ViewChild("grid") public grid: GridComponent;
public data: Object[];
public resizeSettings = { mode: "Normal" };
ngOnInit(): void {
this.data = orderDetails.slice(0, 18);
}
dataBound() {
this.grid.autoFitColumns([]); // autoFitColumns method to autofit all the columns
}
} |
|
export class AppComponent {
@ViewChild("grid") public grid: GridComponent;
public data: Object[];
public resizeSettings = { mode: "Auto" };
ngOnInit(): void {
this.data = orderDetails.slice(0, 18);
}
dataBound() {
this.grid.autoFitColumns([]); // autoFitColumns method to autofit all the columns
}
} |
<ejs-grid
#grid
[dataSource]="data"
allowResizing="true"
height="400"
(load)="load($event)"
(dataBound)="dataBound()"
(resizeStop)="resizeStop($event)"
>
<e-columns>
……..
</e-columns>
</ejs-grid> |
export class AppComponent {
@ViewChild("grid") public grid: GridComponent;
public data: Object[];
public a: Object = {};
public flag: Boolean = true;
ngOnInit(): void {
this.data = orderDetails;
}
dataBound() { //dataBound event
if (this.flag) { // This event will be triggered each time the grid data is modified, so flag variable is used so that this case is executed only at initial.
var columns = this.grid.columns;
for (var i = 0; i < columns.length; i++) {
this.a[(columns[i] as any).field] = (columns[i] as any).width;
}
window.localStorage.setItem("columnWidth", JSON.stringify(this.a)); // we store the grid columns width in the window localStorage at initial rendering
this.flag = false;
}
}
resizeStop(args) { // column resize stop event
// we update and store the grid columns width in the window localStorage while column resizing
this.a[args.column.field] = args.column.width;
window.localStorage.setItem("columnWidth", JSON.stringify(this.a));
}
load() { //load event
var dataBase = JSON.parse(window.localStorage.getItem("columnWidth")); // we get the stored/saved columns width value form the localStorage
if (dataBase) {
var columns = this.grid.columns;
for (var i = 0; i < columns.length; i++) {
var field = (columns[i] as any).field;
(columns[i] as any).width = dataBase[field]; // set the already stored columns width value to the Grid columns to achieve your requirement
}
}
}
} |
I don't want to be that complicated.I only have a button to restore the column width, and the grid has total 10 columns, and only 1 column visible is true, and the visible column width is 50.I make the columns, and call "grid.columns = columns;" and "grid.refresh()".After click the restore button, the only visible columns is showed, but it's width is not 50, it full filled the grid width auto.That's not I want.Do you have idear?
<e-column field='CustomerID' headerText='Customer ID' minWidth='90' width='90' maxWidth='90'></e-column> |