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

The numeric part cannot be parsed as a numeric part of a Pixel unit

1 Answer 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 19 Aug 2011, 11:17 AM
Hi

We are currently experiencing a problem with our grid control when a user switches their language to anything other than en-GB.

The problem is occurring when we hit the search button twice and the columns of the grid attempt to resize, using an auto resize JS function we have registered on the page. This function should resize the columns to the size of the values in the columns themselves.

I have attached the code I believe the problem exists. Can you provide a possible fix for this issue?

function AutoResizeColumns() 
	{
	    var gridMinWidth = 0;
 
	    var grid = window['grid_' + '<%= grd.ClientID %>'];
	    for (var i = 0; i < grid.MasterTableView.Columns.length; i++) {
 
	        var maxColumnSize = 0;
            
            for (var j = 0; j < grid.MasterTableView.Rows.length + 1; j++) {
                var gridRow = j < grid.MasterTableView.Rows.length ? grid.MasterTableView.Rows[j].Control : grid.MasterTableView.HeaderRow;
 
                var textContent = "";
                if (gridRow.cells[i].childNodes.length > 0 &&
                (typeof gridRow.cells[i].childNodes[0].getElementsByTagName == "function" || typeof gridRow.cells[i].childNodes[0].getElementsByTagName == "object")) {
                    var childNodes = gridRow.cells[i].childNodes[0].getElementsByTagName("span");
                    if (childNodes.length > 0) {
                        textContent = childNodes[0].innerText;
                    }
                }
 
                if (textContent != null) {
                    var rowColLength = textContent.trim().length;
                    if (rowColLength > maxColumnSize) {
                        maxColumnSize = rowColLength;
                    }
                }
            }
 
            if (maxColumnSize > 0) {
                gridMinWidth += (maxColumnSize * 7.5);
                grid.MasterTableView.ResizeColumn(i, maxColumnSize * 7.5);
            }
            else {
                gridMinWidth += 2;
                grid.MasterTableView.ResizeColumn(i, 2);
            }
	    }
 
	    document.getElementById(grid.ClientID).style.width = "100%";
	    document.getElementById(grid.MasterTableView.ClientID).style.width = "100%";
 
	    document.getElementById(grid.ClientID).style.minWidth = gridMinWidth + 100;
	    document.getElementById(grid.MasterTableView.ClientID).style.minWidth = gridMinWidth + 100;
	}

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 24 Aug 2011, 11:30 AM
Hi Jonathan,

It is recommended to use functions from the public API of the Grid and it's MasterTableView to be sure that your code will work as expected. Check this help topics:
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-class-members.html
http://www.telerik.com/help/aspnet-ajax/grid-class-members.html

Additionally if you want the size of the columns to depends on their content you could set ClipCellContentOnResize to false and use data format string for your columns like "<nobr>{0}</nobr>". See this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/resizing/defaultcs.aspx
1) Un-check ""
2) Check ""

I hope this helps.

All the best,
Vasil
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or