2

我正在尝试向我的 mvc 网格视图列添加多个设置。我知道如何将一个特定设置应用于列。我浏览了他们的网站文档,但找不到这样的例子。我知道它可以做到,而且可能真的很容易,但在任何地方都找不到它的例子。

@{
 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()

我上面的例子很容易解释。也许我必须在它自己的添加属性上创建我的列,然后手动添加它。不确定,因为这是我第一次使用 MVC Devexpress Gridviews。任何意见是极大的赞赏。

4

4 回答 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
});
于 2013-01-23T21:22:25.197 回答
1

这是另一种方式:

var column = settings.Columns.Add("ColumnA", "ColumnADisplay");
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
column.Width = Unit.Pixel(75);  
于 2013-12-04T17:17:38.797 回答
0

最终不得不自己创建专栏。

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); 
于 2013-01-08T15:55:55.767 回答
0

有什么:

settings.Columns.Add(new MVCxGridViewColumn("ColumnA", MVCxGridViewColumnType.Default)
{
  Caption = "ColumnADisplay", 
  vSortOrder = DevExpress.Data.ColumnSortOrder.Ascending,
  Width = Unit.Pixel(75)
}); 
于 2015-11-30T12:11:05.240 回答