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

AutoResize column needs to remove whiteSpace client side

4 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 17 Nov 2011, 10:18 AM
Hi

I have a radgrid declared on my page:

<radG:RadGrid	ID="grd" 
					Skin="orange" 
					Style="padding-left0px" 
					runat="server" 
					EnableAJAXLoadingTemplate="false" 
					AllowCustomPaging="true" 
					enableasyncrequests="false" 
					AllowPaging="false" 
					PageSize="10"
					AllowSorting="true" 
					AutoGenerateColumns="false" 
					showheaderswhennorecords="true" 
					AllowMultiRowSelection="true" 
					CssClass="GenericDataGrid" 
					applystylesonclient="false"
					OnNeedDataSource="cRadGrid1_NeedDataSource" 
					OnItemDataBound="cRadGrid1_ItemDataBound" 
					OnDataBinding="cRadGrid1_DataBinding"
					OnDataBound="cRadGrid1_DataBound"
					OnSortCommand="cRadGrid1_SortCommand"
					>


Within the grid control we also have a button that auto resizes the columns. What we are trying to achieve is set 1 of these particular columns to a fixed width. We have achieved this however, we cant remove the white-space property from the cell so when the content goes beyond our fixed width the text is automatically carried over into the next line of the cell i.e. a line break.

below code for creating a default column server side:

// create column
					if (!ColumnExists(column, key))
					{
						grd.MasterTableView.Columns.Add(boundColumn);
						boundColumn.DataField = GetDataField(column);
						boundColumn.HeaderText = GetHeaderText(column);
						boundColumn.UniqueName = key;
						boundColumn.SortExpression = GetDataField(column);
						boundColumn.DataFormatString = @"<div id=a title='{0}'>{0}</div>";
 
 
                        if (column == ColumnListBaseEnum.DescriptionOrTitle.ToString())
                        {
                            col.HeaderStyle.Width = Unit.Pixel(438);
                            boundColumn.Resizable = true;
                            col.HeaderStyle.Wrap = false;
                            col.ItemStyle.Wrap = false;
                        }
					}



We have tried to access the column through script like so:

var gridCellStyle = gridRow.cells[i].children[0].getAttribute('currentStyle');
 
                         gridCellStyle.whiteSpace = '';

This returns the attached screenshot error.

Any suggestions would be greatly appreciated.

Regards,
Jonathan

4 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 21 Nov 2011, 11:51 AM
Hi Jonathan,

I am not sure exactly how you are resizing your columns but have you tried using the resize to fit functionality of RadGrid. If not, try it and let us know if the issue that you are encountering persists there, too:
Resizing Columns (last section)
resizeToFit()

Greetings,
Tsvetina
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
0
Mahesh
Top achievements
Rank 1
answered on 21 Aug 2012, 05:04 AM
Hi  Tsvetina,

I am facing problem that.....
On resizing of one column    (of Telerik mvc grid )  other columns are also resizing  ....How to avoid this.... or else pls tell me how to get width of the column  in the client events of grid or in javascript........
Pls inform me....I am waiting for your reply 
0
Shinu
Top achievements
Rank 2
answered on 21 Aug 2012, 05:40 AM
Hi Mahesh,

I suppose you need the column width on Column resizing.

ASPX:
<ClientSettings>
    <ClientEvents OnColumnResizing="OnColumnResizing" />
    <Resizing AllowColumnResize="true"   />
</ClientSettings>

Javascript:
<script type="text/javascript">
    function OnColumnResizing(sender, args)
    {
        var width = args.get_gridColumn()._columnResizer._currentWidth;
    }
</script>

Thanks,
Shinu.
0
Mahesh
Top achievements
Rank 1
answered on 21 Aug 2012, 06:47 AM
Hi Shinu,

Thanks for your response.
But I want width of the all columns with name so that I can adjust my content of the toolbar.....and I am using Razor Engine....
Pls reply I fu have any kind of solution...

Thanks for your reply once again...


Regards,
Mahesh
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Mahesh
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or