grid.dataBound = () => {
if (grid.columns.length > 6) {
grid.autoFitColumns();
}
} |
I have a similar problem, I have a few columns that I would like to autofit, and I have one column that I would like to take the remaining space.
Is this possible?
I have set the big columns width to 100%, and explicitly name the columns to autofit, but when autofitting the grid seems to ignore the 100% on the column I want to be big. Is there a way I can give that column the 100% after autofitting?
Hi Tor,
Thanks for contacting Syncfusion support.
Query: I have a few columns that I would like to autofit, and I have one column that I would like to take the remaining space.
Based on your requirement you want to autofit only particular columns in the Grid. You can achieve this by passing the column fields in the autoFitColumns method.
dataBound:
https://ej2.syncfusion.com/javascript/documentation/api/grid/#dataBound
autoFit specific columns: https://ej2.syncfusion.com/javascript/documentation/grid/columns/auto-fit-columns/
Also, you want one column to adapt the remaining white space in the Grid. You
can achieve this by setting the column width as auto and minWidth
in the column settings.
[index.js] dataSource: data, columns: [ { field: 'OrderID', headerText: 'Order ID', width: 120, textAlign: 'Right', }, { field: 'CustomerName', headerText: 'Customer Name Detailsss', width: 150, }, { field: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }, { field: 'ShipCountry', headerText: 'Ship Country', width: 150 }, { field: 'ShipAddress', headerText: 'Ship Address', minWidth: '200', width: 'auto', }, ], dataBound: dataBound, }); grid.appendTo('#Grid');
function dataBound(args) { // adjust the columns based on minwidth var tgridWidth = this.widthService.getTableWidth(this.getColumns()); this.widthService.setMinwidthBycalculation(tgridWidth); // autofit all the columns except the auto width column (ShipAddress) this.autoFitColumns(['OrderID', 'CustomerName', 'Freight', 'ShipCountry']); }
|
sample: https://stackblitz.com/edit/davn41-cegvdr?file=index.js
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S