Reputation: 105
I have a dynamically generated MVC3 grid that is populated from a ViewModel. I need to add editing to the grid and cant get it to even go into edit mode.
Also I need to be able to make some of the columns readonly.
My code is below:
@(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))
)
My viewmodel definition
public class DeliveriesGridViewModel
{
public DataTable Data { get; set; }
public IEnumerable<GridColumnSettings> Columns { get; set; }
}
Thanks for the help
Upvotes: 0
Views: 515
Reputation: 20233
If you are binding to a DataTable or something similar make sure that the properties you bind the columns to does not contains white spaces.
i.e. "Delivery Name" should be "DeliveryName"
Upvotes: 1