This is a migrated thread and some comments may be shown as answers.

Column spacing

3 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 23 Feb 2012, 12:17 PM
is there a straightforward way to have columns auto resize to cater for the cell contents rather than them all being the same width regardless?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Feb 2012, 12:23 PM
Hello,

Check the following demo.
Grid / Column/Row Resize/Reorder

Thanks,
Princy.
0
Mark
Top achievements
Rank 1
answered on 23 Feb 2012, 01:55 PM
thanks

but was seeking something more dynamic rather than user intereaction.

for example a simple grid with say 3 text columns but 10 numeric columns, id like the numeric columns to be smaller width, i can of course do this by checking each column name and setting width but hoped there might be a more efficient way.
0
Veli
Telerik team
answered on 27 Feb 2012, 12:29 PM
Hi Mark,

RadGrid provides the so-called "best-fit" size for grid columns. This client-side functionality calculates the best-fit size of the grid columns based on their content. You can use it to render your grid in an optimal layout. However, as this is a client-side feature, you need to use some javascript to find all column on the client and resize them to their best fit. This needs to happen when the grid loads initially. Try the following javascript on your page (RadGrid1 is the server-side ID of the RadGrid control):

function pageLoad() {
    var grid = $find("<%= RadGrid1.ClientID %>");
    var columns = grid.get_masterTableView().get_columns();
    for (var i = 0; i < columns.length; i++) {
        columns[i].resizeToFit();
    }
}

Sample test page is attached to demonstrate the working example.

Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Veli
Telerik team
Share this question
or