2

I am attempting to add more than one setting to my mvc grid view columns. I know how to apply one specific setting to a column. I went through their website documentation and was unable to find an example of this. I know it can be done and is probably really easy but can't find an example of it anywhere.

@{
 var grid = Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gvMyGridView";
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        //Allows sorting etc
        settings.CallbackRouteValues = new { Controller = "Home", Action = "MyGridPartial" };
        settings.ClientSideEvents.BeginCallback = "OnBeginCallback";

        settings.Columns.Add("ColumnA").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
        //settings.Columns.Add("ColumnA").Width = Unit.Pixel(75);
        //As you can see above i want sort order set and the width set but am unable to do so
        settings.Columns.Add("ColumnB").Width = Unit.Pixel(175);
        settings.Columns.Add("ColumnC").Width = Unit.Pixel(175);

        //Filter settings
        settings.Settings.ShowFilterRow = true;
        settings.Settings.ShowFilterRowMenu = true;
        settings.CommandColumn.ClearFilterButton.Visible = true;

        //Inline editing 
        settings.KeyFieldName = "Id";

    });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()

My example above is pretty self explanatory. Maybe I have to create my column on its own add properties to it then add it in manually. Unsure as this is my first run with MVC Devexpress Gridviews. Any advice is greatly appreciated.

4 Answers 4

16
settings.Columns.Add(column =>
{
column.FieldName = "Title";
column.Width = System.Web.UI.WebControls.Unit.Percentage(30);
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
//other settings for column
});
Sign up to request clarification or add additional context in comments.

Comments

1

Here is another way:

var column = settings.Columns.Add("ColumnA", "ColumnADisplay");
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
column.Width = Unit.Pixel(75);  

Comments

0

Ended up having to create the column myself.

var column = new MVCxGridViewColumn("ColumnA", MVCxGridViewColumnType.Default);
column.Caption = "ColumnADisplay";
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
column.Width = Unit.Pixel(75);        
settings.Columns.Add(column); 

Comments

0

What's with:

settings.Columns.Add(new MVCxGridViewColumn("ColumnA", MVCxGridViewColumnType.Default)
{
  Caption = "ColumnADisplay", 
  vSortOrder = DevExpress.Data.ColumnSortOrder.Ascending,
  Width = Unit.Pixel(75)
}); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.