Search Find anything about our product, documentation, and more. Blazor Components | 70+ Native UI Controls | Syncfusion® https://www.syncfusion.com/blazor-components The Syncfusion® native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps. .NET PDF Framework | C# / VB.NET PDF API | Syncfusion® https://www.syncfusion.com/pdf-framework/net .NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET. 155+ Xamarin UI controls for iOS, Android & UWP apps | Syncfusion® https://www.syncfusion.com/xamarin-ui-controls Over 155 Xamarin UI controls to create cross-platform native mobile apps for iOS, Android, UWP and macOS platforms from a single C# code base. My Dashboard SIGN OUT
Home
Forum
ASP.NET MVC (Classic)
Set column widths, wrap text
Set column widths, wrap text
7 Replies
5 Participants
Created by JLJerry Lawrence
PlatformASP.NET MVC (Classic)
PlatformASP.NET MVC (Classic)
ControlGrid
Created OnSep 1, 2009 04:27 PM UTC
Last Activity OnNov 16, 2009 04:33 PM UTC
Want to subscribe? SIGN IN
In the MVC grid, I would like to set the column widths to a fixed size. I have tried this in the controller:gridModel.TableDescriptor.Columns[1].Width = 20;It appears that the columns are auto sizing but I can't find where to turn autosizing columns off. There is an AllowColumnResize in GridTableDescriptor, but I'm not sure where/how to set that.If the columns are fixed width, the text in the columns needs to auto wrap in the cell - which means the cell height needs to be adjusted. Is this doable?Thanks,Jerry SIGN IN To post a reply. 7 RepliesOldest firstBMBalaji M Syncfusion Team September 2, 2009 09:37 AM UTC Hi Jerry,Thank you for your interest in syncfusion products.I would like to set the column widths to a fixed sizeWe regret to let you know that currently, we don't support column width in the current version. We will implemented this in our forthcoming release Essential Studio.I have created an simple workaround sample to reported column width issue.Please find the sample from the below link.http://files.syncfusion.com/support/grid_mvc/Incidents/F89659/MVC_SampleGrid.zipPlease refer the code snippet from the below.[js] Sys.Application.add_load(function() { //Set columnIndex, width var columnIndex = 2; var colWidth = 450; //Find the table header cells var th = $($($('#Grid1').find("thead:first")[0]).find("tr:last")).find("th"); //set the column header width var widthDiff = colWidth - th[columnIndex].offsetWidth; th[columnIndex].style.width = colWidth + "px"; //find the div element inside the header and update the width [Note: calculate the padding values,here padding value is 11] var div = $(th[columnIndex]).find("div"); $(div[0]).width(colWidth - 11 + "px"); //Update the Grid width by the modified column width $("#Grid1")[0].style.width = parseInt($("#Grid1")[0].style.width) + widthDiff + "px"; });2.Autosizing columns off We suggest you to use AllowResizing property in GridPropertyModel to enable/disable the resizing feature.3.Columns needs to auto wrap in the cellWe regret to let you know that currently, we don't support Wrap Text in the current version. We will implemented this in our forthcoming release Essential Studio.Please let me know if you have any concerns.Regards,M. Balaji. SPScott PopovicNovember 10, 2009 03:02 AM UTC Hi, I tried this workaround but get an error "Microsoft JScript runtime error: Object expected" on the line var th = $($($('#RosterGrid').find("thead:first")[0]).find("tr:last")).find("th");where RosterGrid is the name of the grid control. SMSindhuja M Syncfusion Team November 10, 2009 12:01 PM UTC Hi Henryk ,Thank you for your interest in Syncfusion products.I am afraid that I am unable to reproduce the reported issue. I have created a simple sample to test this issue and I am able to deal with the column width issue successfully and the sample is available from below link.http://files.syncfusion.com/support/grid_mvc/Incidents/F89659/SampleGrid.zipPlease have a look at the above sample and if still the issue exists, could you please try reproducing it in the above sample and send us the modified sample so that we could sort out the cause of the issue and provide you a solution or share your sample with us?Please let me know if you have any concerns.Thanks and Regards,Sindhuja.M SPScott PopovicNovember 11, 2009 05:03 AM UTC Hi,After installing latest version (7.403.0.20) of the grid component and running the sample project I now get an error "Invalid argument." on the last line of the view script, line:$("#Grid1")[0].style.width = parseInt($("#Grid1")[0].style.width) + widthDiff + "px";Click continue and it seems to do its thing. Haven't tried running it outside the dev environment yet however.Project attached.Cheers,Henryk.MVC_SampleGrid_Henryk_9a5fee99.zip BMBalaji M Syncfusion Team November 12, 2009 12:02 PM UTC Hi HenrykThank you for your interest in Syncfusion products.Our Essential Grid have been revamped to provide an enhanced support to extensive client side functionality. The reported issue raised because of RegisterClientMvcResourceManager. Our current [7.403.0.20] grid uses new MvcStaticResourceManager to register the css and scripts required to display and add functionality to the controls.Add the Resource Manager to the Site.Master page under the tag as follows...... we suggest you to add your Sys.Application.add_load function (ie. column width funtion) after the RegisterStaticResources call method in site.master.Refer the below code snippet, which illustrates this................ Please refer the updated sample from the below location.http://files.syncfusion.com/support/grid_mvc/Incidents/v7.4.0.20/F89659/MVC_SampleGrid.zipWe would also suggest you to refer the below documentation link for more details.http://help.syncfusion.com/User%20Interface/ASP.NET%20MVC/GridPlease let me know if you have any concerns.Regards,M. Balaji. HSHenryk SchneiderNovember 12, 2009 02:04 PM UTC Hi,This works fine on views where the grid exists, but when I load a page without the grid, I get an error :Microsoft JScript runtime error: 'offsetWidth' is null or not an object.On the line: var widthDiff = colWidth - th[columnIndex].offsetWidth;I'm assuming this is because the script is in the site.master file. So I just put that and everything below it in an if block:if (th.length != 0) {...}I'm not sure if there's a better way to get around it.Also, after all this, I have realised I really need the auto wrap to work on a cell, because when we get some long text, even tthough I've set the column, it gets pushed out anyway, also pushing out the following columns. Thanks.H BMBalaji M Syncfusion Team November 16, 2009 04:33 PM UTC Hi Henryk,We regret for the delayed response.The reported issue raised due to non-existence of grid in the View. We suggest to use the following code snippet to validate the Grid existence.[.js]$('#Grid1').length>0Refer the below code snippet, which illustrates this.[.js] Sys.Application.add_load(function() { //Set columnIndex, width var columnIndex = 2; var colWidth = 450; //Validate the Grid appearance if ($('#Grid1').length > 0) { //Find the table header cells var th = $($($('#Grid1').find("thead:first")[0]).find("tr:last")).find("th"); //set the column header width var widthDiff = colWidth - th[columnIndex].offsetWidth; th[columnIndex].style.width = colWidth + "px"; //find the div element inside the header and update the width [Note: calculate the padding values,here padding value is 11] var div = $(th[columnIndex]).find("div"); $(div[0]).width(colWidth - 11 + "px"); //Update the Grid width by the modified column width $("#Grid1")[0].style.width = parseInt($("#Grid1")[0].style.width) + widthDiff + "px"; } }); Please refer the updated sample from the below link.http://files.syncfusion.com/support/grid_mvc/v7.4.0.20/F89659/MVC_SampleGrid.zipPlease let us know if you have any concerns.Regards,M. Balaji Need More Help?
Get personalized assistance from our support team.
Contact Support SIGN IN To post a reply.
7 Replies
5 Participants
Want to subscribe? SIGN IN
Created by JLJerry Lawrence
PlatformASP.NET MVC (Classic)
ControlGrid
Created OnSep 1, 2009 04:27 PM UTC
Last Activity OnNov 16, 2009 04:33 PM UTC
Need More Help?
Get personalized assistance from our support team.
Contact Support 12/17/2025 09:17:44 AM Sun, 15 December 2024 03:30:00 UTC Sun, 15 December 2024 03:30:00 AM Wed, 16 Feb 2022 04:59:00 UTC