user2268992
user2268992

Reputation: 1

Kendo UI Grid Row Template

I had a problem on how to apply row Template data binding into it. I not sure what is the syntax to do so. I am using server binding mode. Below is my code

@(Html.Kendo().Grid((IEnumerable<IcmsViewModel.LookupView>)ViewData["LookupView"]) // Bind the grid to the Model property of the view
  .Name("Grid")
  .CellAction(cell =>
      {

        if (cell.DataItem.Active == false)
        {
            cell.HtmlAttributes["style"] = "background-color: red";

        }

      }
  )
  .Columns(columns =>
  {
      columns.Bound(p => p.LookupValue).ClientTemplate(" ").Title("Short Name").Width(300);
      columns.Bound(p => p.Description).Width(300);
      columns.Bound(p => p.Active).Width(300);
      columns.Command(command => { command.Edit(); command.Destroy(); });

  })
**.RowTemplate(rows =>
                "<tr><td>Testing</td>" +
        "<td colspan=\"2\"><input type=\"button\" name=\"ClickMe\" value=\"ClickMe\" onclick=\"javascript:window.open(('/Test/ViewTest'), 'ViewTest', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');\"/></td>" +
        "<td>Name</td></tr>"
)**
  .ToolBar(commands => commands.Create())
  .Groupable()
  .Pageable()
  .Sortable()
    //.Filterable()
  .Scrollable(x => x.Height(600))
  .Editable(editable => editable.Mode(GridEditMode.InLine))
      .DataSource(dataSource => dataSource
            .Server()
             .Model(model => { model.Id(p => p.Id); model.Field(p => p.Id).Editable(false); })
            .Create(create => create.Action("CreateLookup", "Icms"))
            .Read(read => read.Action("Lookup", "Icms"))
            .Update(update => update.Action("UpdateLookup", "Icms"))
            .Destroy(destroy => destroy.Action("Destroy", "Sample"))
        )

)

Currently I hard code the value in the row template, how can I bind it with the data in database, if i want to apply the row template.

Example .RowTemplate(rows => "p.LookupValue" + "" + "p.Description" )

Please help me on this as I am new to kendo UI. Thanks a lot.

Upvotes: 0

Views: 4167

Answers (1)

Samuel Caillerie
Samuel Caillerie

Reputation: 8275

Why don't you use Template on the column definition :

.Columns(columns =>
{
    columns.Bound(p => p.LookupValue)
           .Template(@<text>@item.LookupValue @item.Description</text>).Title("Short Name").Width(300);
    columns.Bound(p => p.Active).Width(300);
    columns.Command(command => { command.Edit(); command.Destroy(); });  
})

Upvotes: 6

Related Questions