We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid - setting width of each column

Thread ID:

Created:

Updated:

Platform:

Replies:

115843 Feb 10,2014 11:15 AM UTC Feb 18,2014 05:52 AM UTC ASP.NET MVC (Classic) 1
loading
Tags: Grid
Dikshit Gokhale
Asked On February 10, 2014 11:15 AM UTC

Hi,


We are using Syncfusion grid and binding data source with view data as below. I want to set width for each column. The data contained in view data is dynamically generated and varies. In such scenario how can we set the width of each column? Please help.

 @(Html.Syncfusion().Grid<System.Data.DataRow>(str)
                        .Datasource((System.Data.EnumerableRowCollection)ViewData["vwdta_" + str])
                        .Caption(str)
                        .EnableOnDemand()
                        .TotalRecordCount(totalRecordcount)
                        .EnablePaging().PageSettings(p => p.PageSize(pagesize))
                        .EnableSorting()
                        .AutoFormat(Skins.Office2007Silver)
                        .EnableFiltering()
                        .AllowResizing(true)
                        .EnableScrolling()
                        .AllowAutoWrap(false)
                        .ClientSideEvents(c=>c.OnActionBegin("Begin"))  )


Thank you
Dikshit

Abdul Matin M [Syncfusion]
Replied On February 18, 2014 05:52 AM UTC

Hi Dikshit,

 

Thanks for your interest in Syncfusion products.

 

We have analyzed your requirement and it can be achieved by iterating each column and we can set the width for each column dynamically. Please refer the below code snippet.

[CSHTML]

.Column(cols =>

    {

        if ((HttpContext.Current.Session["datasource"] as DataTable) != null)

        {

            System.Data.DataTable dataTable = (HttpContext.Current.Session["datasource"] as DataTable);

            foreach (System.Data.DataColumn col in dataTable.Columns)

            {

                cols.Add(col.ColumnName).HeaderText(col.Caption).Width(200);

            }

        }

    })

For your convenience we have prepared a simple sample based on the code snippet you have provided and the same can be downloaded from the link below.

 

Please use the sample and get back to us if you have any other queries.

 

Please let us know if you need any further assistance.

 

Regards,

Abdul Matin M


Attachment: SetWidthSample_c87dd3cb.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;