|
[app.component.html]
<ejs-grid #grid [dataSource]='data' height='400' width='700' [resizeSettings]="resizeSettings" [allowResizing]="true">
<e-columns>
<e-column field='LineNo' headerText='#' width='50' minWidth='50' maxWidth="120">
<ng-template #template let-data>
{{data.index}}
</ng-template>
</e-column>
<e-column field='OrderID' headerText='Order ID' width='150' minWidth='50' maxWidth="180"></e-column>
<e-column field='CustomerName' headerText='Customer Name' width='120' minWidth='50' maxWidth="150"></e-column>
<e-column field='CustomerID' headerText='Customer ID' width='200' minWidth='50'></e-column>
<e-column field='ShipCity' headerText='Ship City' width='120' minWidth='50' maxWidth="150"></e-column>
<e-column field='ShipCountry' headerText='Ship Country' width='120' minWidth='50' maxWidth="150"></e-column>
</e-columns>
</ejs-grid>
[app.component.ts]
btnClick() {
. . . .
this.grid.columns = newcolumns;
this.grid.refreshColumns();
this.grid.autoFitColumns();
} |
|
[app.component.ts]
btnClick() {
var newcolumns: any[] = [];
var columns = this.grid.columns;
for (var i = 0; i < columns.length; i++) {
var item: any = Object.assign({}, this.grid.columns[i]);
if (i == 0) {
item.width = 45;
item.visible = true;
} else if (i == 1) {
item.width = 150;
item.visible = true;
} else {
item.visible = false;
}
newcolumns.push(item);
}
this.grid.columns = newcolumns.slice(0);
this.grid.refreshColumns();
this.grid.autoFitColumns();
var columns = this.grid.columns;
setTimeout(
function() {
for (var i = 0; i < columns.length; i++) {
var col = newcolumns[i];
if (newcolumns[i].visible) {
this.grid.widthService.setColumnWidth(col);
}
}
}.bind(this),
100
);
} |
|
btnClick() {
var newcolumns: any[] = [];
var columns = this.grid.columns;
for (var i = 0; i < columns.length; i++) {
var item: any = Object.assign({}, this.grid.columns[i]);
if (i == 0) {
item.width = 50;
item.visible = true;
newcolumns.push(item);
} else if (i == 1) {
item.width = 50;
item.visible = true;
newcolumns.push(item);
}
}
this.grid.columns = newcolumns.slice(0);
this.grid.refreshColumns();
this.grid.autoFitColumns();
var columns = this.grid.columns;
setTimeout(
function() {
var sum = 0;
for (var i = 0; i < columns.length; i++) {
var col = newcolumns[i];
if (newcolumns[i].visible) {
sum = sum + newcolumns[i].width; //calculate the total width of the column
this.grid.widthService.setColumnWidth(col);
}
}
this.grid.getHeaderTable().style.width = sum+"px"; //set the total width to the table
this.grid.getContentTable().style.width = sum+"px";
}.bind(this),
100
);
}
|
Hi,
Is there a way not to use the timeout, because the timeout is not very reliable.
Another question, why must call the autofitcolumns function first ? Is there a way avoid to call the autofitcolumns? Because I have set the columns width.
Can I not call the auto fit function? The grid content total width can be sumed by the visible column width, no need to must call the auto fit, is that right?
If you call auto fit once and then update the correct column width, the grid column on the interface will flash twice. I am dealing with this problem.
Do you have a better solution for restore the specific column widths?
|
<style>
.e-grid .e-headercell.e-lastcell {
border-right-style: solid;
border-right-color: #e0e0e0;
border-right-width: 1px;
}
.e-grid .e-gridcontent td:last-child {
border-right-style: solid;
border-right-color: #e0e0e0;
border-right-width: 1px;
}
}
</style>
|