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. Image for the cookie policy date
close icon

ejGrid setWidthToColumns

Hello,
I am trying to set ej Grid column width with setWidthToColumns method. Its not working.  The goal is if user changes the column width, we want to user to reset all columns width to default by clicking a button.

 Here is the code snippet.

                        var grid = $("#FlatGrid").ejGrid("instance");
                        grid.setWidthToColumns();
                        grid.refreshContent();


Please advise.

Thanks

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team October 10, 2016 05:37 AM UTC

Hi Arun, 

Thanks for contacting Syncfusion support. 

If you want to change the column width dynamically, use columns method of ejGrid. In this sample we change the column width of an particular column in the button click. 

Find the code example and sample: 


@Html.EJ().Button("buttonnormal").Size(ButtonSize.Normal).Text("Button").ClientSideEvents(e => e.Click("Click")) 
 
@(Html.EJ().Grid<object>("FlatGrid") 
    .Datasource((IEnumerable<object>)ViewBag.datasource) 
    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
    ------------------ 
   .AllowPaging() 
    .Columns(col => 
     {  
        --------------------------------- 
       col.Field("ShipCity").HeaderText("Ship City").TextAlign(TextAlign.Right).Width(80).Priority(2).EditType(EditingType.Dropdown).ValidationRules(v => v.AddRule("required", true)).Add(); 
       ------------------------------------ 
    }) 
    ) 
 
---------------------------------------------- 

function Click(args) { 
        var gridobj = $("#FlatGrid").ejGrid("instance"); 
        gridobj.model.columns[1].width = 100; 
        var columns = gridobj.model.columns[1]; 
        gridobj.columns(columns); 
    } 


Refer to the Help document for the columns method. 


Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Live Chat Icon For mobile
Up arrow icon