我有一个从 ViewModel 填充的动态生成的 MVC3 网格。我需要向网格添加编辑,甚至无法进入编辑模式。
此外,我需要能够使某些列只读。
我的代码如下:
@(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; }
}
谢谢您的帮助