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

Remove column width in javascript

2 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 24 Apr 2014, 02:59 PM
I am working on a project where at times I need to set the column width to a fixed value in javascript, and then I need to remove it, so that it expands 100%.  Setting the fixed width is easy using the built in js function...

grid.resizeColumn(cellIndex, width);

After this I also need to be able to remove that width so that the column will expand as needed.  Any suggestions on how to accomplish this?

2 Answers, 1 is accepted

Sort by
0
Venelin
Telerik team
answered on 29 Apr 2014, 07:57 AM
Hi Brian,

Here I implemented a custom function that will reset grid back to its initial state (no column widths and 100% expanded)

JavaScript:

function clearWidths() {
   
    var grid = $find('<%=gvTest.ClientID%>'),
        mtv = $find('<%=gvTest.ClientID%>').get_masterTableView(),
        cols = mtv.ColGroup.Cols;
 
    for(var i = 0, len = cols.length; i < len; i++){
        cols[i].style.width = "";
    }
 
    grid.get_element().style.width = "auto";
    mtv.get_element().style.width = "100%";
}

You have to manually iterate through all <col> elements and set the width to "" empty string. After that, as you can see the width of the grid should be reset to auto and the master table - to 100%.

Since you haven't posted your grid declaration I assume these settings based on the explanation:

ASPX:

<telerik:RadGrid runat="server" ID="gvTest" OnNeedDataSource="RadGrid_NeedDataSource">
    <ClientSettings>
        <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true"/>
       
    </ClientSettings>
</telerik:RadGrid>

I hope this helps.

Regards,
Venelin
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
Andres
Top achievements
Rank 1
answered on 27 Feb 2018, 09:52 AM

Thanks Venelin.

I was looking for this.

Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Venelin
Telerik team
Andres
Top achievements
Rank 1
Share this question
or