0
votes

I have a problem with edit template data bind for kendo grid. I have binded my grid to model which is DataTable(it must be DataTable because all cloumns must be generated dynamic - I do not know the schema), I added export, sortable, pages etc. I also added edit button, and defined another cshtml file with edit template. It all works almost perfect. One problem is that I receive the empty model for edit template. View:

@(Html.Kendo().Grid(Model.Data)
   .Name("OpertionalViewGrid")
   .DataSource(dataSource => dataSource
     .Ajax()
    .ServerOperation(false)
    .Events(events => events.Error("error_handler"))
    .Model(model =>
    {
        model.Id(p => p.Row[0]);
        if (Model.Data != null)
        {
            foreach (System.Data.DataColumn column in Model.Data.Columns)
            {
                var field = model.Field(column.ColumnName, column.DataType);
            }
        }
    })
    .PageSize(20)
    .Read(read =>
 read.Action("Export_Read","OperationalView").Data("getRow"))
    .Update(up => up.Action("UpdateRow", "OperationalView").Data("getRow"))
)
   .Columns(c =>
   {
       if (Model.Data != null)
       {
           int index = 0;
           foreach (System.Data.DataColumn column in Model.Data.Columns)
           {
               var col = c.Bound(column.ColumnName).Width("300px");
               if (index < 2)
               {
                   col.Locked(true).Lockable(false);
               }

               index++;
           }
           c.Command(command => { command.Edit();}).Width(100);
       }
   })
.Editable(editable => editable
    .Mode(GridEditMode.PopUp)
    .TemplateName("OperationalViewEditor")
    )
.Scrollable()
.Reorderable(reorder => reorder.Columns(true))
.Resizable(r => r.Columns(true))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.HtmlAttributes(new { style = "height:100%" })
.Pageable()
.Navigatable()
.Sortable()
.Groupable(g => g.ShowFooter(true))
.ToolBar(tools => tools.Excel())
.Excel(excel => excel.AllPages(true))
.ToolBar(tools => tools.Pdf())
    .Pdf(pdf => pdf
        .AllPages()
        .AvoidLinks()
        .PaperSize("A4")
        .Scale(0.8)
        .Margin("2cm", "1cm", "1cm", "1cm")
        .Landscape()
        .RepeatHeaders()
        .TemplateId("page-template")
        .FileName("Export.pdf")
    )
         )   

I have also my getRow function:

<scriprt>
function getRow()
{

    var grid = $('#OpertionalViewGrid').data('kendoGrid');
    var selectedItem = grid.dataItem(grid.select());
    return selectedItem;
} </script>

In my controler I have:

public ActionResult Export_Read([DataSourceRequest]DataSourceRequest request)
    {
        var ovs = new OperationalViewService();

        return Json(ovs.Read()/*.ToDataSourceResult(request)*/);
    } 
public ActionResult UpdateRow([DataSourceRequest] DataSourceRequest dsRequest, DataRowView row)
    {

        var t = 5;

        return Json(row/*ModelState.ToDataSourceResult()*/);
    }

And my edit template:

@model System.Data.DataRowView

<h3>Customized edit template</h3>
@if(Model == null)
{
   <label> null</label>
}
else
{
<label> not null!!!!!!</label><br />
@Html.Label(Model.DataView.Table.Columns.Count.ToString())<br />
@Html.Label(Model.ToString())<br />
@Html.Label(Model.Row.Table.Columns.Count.ToString())<br />
}
@for (int i = 0; i < Model.DataView.Table.Columns.Count; i++)
{
@Html.LabelFor(model =>       model.DataView.Table.Columns[i].ColumnName.ToString())
@Html.LabelFor(model => model.Row[i].ToString())
<br />
}

So.. when I click Edit button, I get a window with proper header, with note "01234 not null!! 0 DataRowView 0 " So I conclude that model is of proper type, one problem is to pass my selected row. I am very new to web and Kendo/telerik so my question: how to send my selected grid row to edit template? Another question is: why when I click "edit" i do not get into UpdateRow action in my controler?

1
Is it beacuse my editor templates are rendered rifht after page load when no row is selected?Kula

1 Answers

0
votes

I have ommited the problem by using edit mode InCell - one important note is to specify the column type, as shown here: http://www.telerik.com/forums/inline-batch-crud-fails-with-datatable-model