2012-08-01 45 views
0

我有一个动态生成的MVC3网格,从ViewModel填充。我需要将编辑添加到网格,并且无法使其进入编辑模式。编辑动态生成Telerikmvc3网格

此外我需要能够使一些列只读。

我的代码如下:

@(Html.Telerik() 
    .Grid<System.Data.DataRow>(Model.Data.Rows.Cast<System.Data.DataRow>()) 
    .HtmlAttributes(new { style = "width: 2500px" }) 
    .Name("Grid") 
     .ToolBar(tb => tb.Template("Outstanding Orders")) 
     .DataKeys(dataKeys => dataKeys.Add("DeliveryID")) 
    .Columns(columns => 
    { 
     columns.Command(commands => 
     { 
      commands.Edit().ButtonType(GridButtonType.ImageAndText) 
       .HtmlAttributes( 
       new 
       { 
        style = "width: 60px; min-width: 40px; background: #0066FF" 
       }); 
     }).Width(100).Title("Commands"); 
     columns.Command(commandbutton => 
     { 
      commandbutton.Select().ButtonType(GridButtonType.ImageAndText) 
       .HtmlAttributes(
       new 
       { 
        style = "width: 60px; min-width: 40px; background: #0066FF" 
       }); 

     columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>); 
    }) 
    .DataBinding(dataBinding => dataBinding.Server() 
       .Select("_DeliveryGrid", "Deliveries") 
      .Update("Save", "Deliveries")) 
    .Editable(editing => editing.Mode(GridEditMode.InLine)) 
    .Sortable(settings => settings.Enabled(true)) 
    .Scrollable(c => c.Height("9000px")) 
    .EnableCustomBinding(true) 
    .Resizable(resize => resize.Columns(true)) 
) 

我的视图模型定义

public class DeliveriesGridViewModel 
{ 
    public DataTable Data { get; set; } 
    public IEnumerable<GridColumnSettings> Columns { get; set; } 
} 

感谢您的帮助

+0

“不能得到它,甚至进入编辑模式,”你这是什么意思? – Tx3 2012-08-01 13:42:47

+0

@ Tx3 - 当我点击“编辑”按钮时,它发布到我的控制器以获取数据,然后返回到网格并且不进入编辑模式。它只是再次显示网格。 – Squeal 2012-08-01 18:24:02

+0

控制台中的任何错误(浏览器中的F12)? – Tx3 2012-08-02 07:41:58

回答

1

如果绑定到一个类似于的DataTable什么确保了将列绑定到的属性不包含空格。

即“交货名称”应为“DeliveryName”

+0

所以列标题/标题不能在它们中有空格,那是你在说什么? – Squeal 2012-08-08 03:17:43

+0

我删除了列中的空格。现在我收到此错误 SyntaxError:标识符在数字文字后立即启动 这发生在以数字开头的列上。 Ex 8GHSDimm。 关于这个的任何想法? 谢谢 – Squeal 2012-08-08 04:35:44

+0

我按照您的建议移除了所有空格,并以一个数字开头的列将_放在前面。非常感谢您的信息,我一直在努力尝试着解决这个问题很长一段时间。但它仍然不会进入编辑模式。当我点击编辑按钮时,它只是返回到我的网格。 – Squeal 2012-08-08 22:59:44