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

Get column width after databind

3 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Jesse asked on 08 Jul 2014, 09:31 PM
I have columns that are sized to fit the data, I am not setting the widths. With this format, is there a way to find the widths of the columns once all of the data has been bound to the grid?

I'm trying to truncate text and append an ellipsis (...), but the user can choose to hide or show columns, so I can't hard code the columns widths. I need to find a way to find the widths, and calculate the number of characters to allow from that.

rgResults.Columns[i].HeaderStyle.Width.Value

is returning 0.0

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 11 Jul 2014, 09:34 PM

Hello Jesse,

I have already answered the same question in the forum thread you have opened:

Indeed using the pointed code you can retrieve the column width of the columns that have specified width. You can retrieve the widths of all columns on client-side, store them in an object and store this object in a hidden field. Then you can access this field on server and get the desired widths.

Regarding accessing RadGrid client-side:
​Coould you confirm that you have added RadScriptManager control on top of the page in which the grid controls is added? Put the Javascript code for referencing the grid at the bottom of the page and let me know about the result.

You can also refer to the article below for more information how to reference controls:
http://www.telerik.com/help/aspnet-ajax/grid-getting-client-object.html

Regards,

Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jesse
Top achievements
Rank 1
answered on 15 Jul 2014, 09:11 PM
Pavlina. How do I get the width on client side?

I did this, but I'm still getting blank for the widths that are dynamically set:

var grid = $find("<%= rgResults.ClientID %>");
var mtv = grid.get_masterTableView();
var columns = mtv.get_columns();
for (var i = 0; i < columns.length; i++) {
    var element = columns[i].get_element();
    alert(element.width);
}
0
Accepted
Galin
Telerik team
answered on 18 Jul 2014, 04:01 PM
Hello Jesse,


You can get the width of the columns by using the method offsetWidth as it is shown bellow
    var grid = $find("<%= RadGrid1.ClientID %>");
    var mtv = grid.get_masterTableView();
    var columns = mtv.get_columns();
    for (var i = 0; i < columns.length; i++) {
        var element = columns[i].get_element();
        alert(element.offsetWidth);
    }
}

Also in case you want to resize a column please use the method resizeColumn. For more information please refer to this demo page.

I hope this helps.

Regards,
Galin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Jesse
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Jesse
Top achievements
Rank 1
Galin
Telerik team
Share this question
or