Home > database >  Call function in KendoGrid Editable property
Call function in KendoGrid Editable property

Time:08-11

I have the following code, where to the columns I add the property of Editable, where to know if it is true or false I will send to call a JS function, what I want to send as parameter the value of the columan UnitsInStock. How can I set it as a parameter in the call the function? currently does not work.

 @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
.Name("grid")
.Columns(columns =>
{
    columns.Bound(p => p.ProductName).Editable("funcion(UnitsStock)");
    columns.Bound(p => p.UnitPrice).Width(120);
    columns.Bound(p => p.UnitsInStock).Width(120);
    columns.Bound(p => p.Discontinued).Width(120);
})
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.ProductID))
    // ...
)

CodePudding user response:

The Editable() configuration expects the name of the JS function that would specify if the filed is editable or not. By default, the function receives the dataItem for the row, so you can just do the following - example:

columns.Bound(p => p.ProductName).Editable("isEditable");
...
<script>
  function isEditable(dataItem){
     return dataItem.UnitsInStock % 2 == 0 // logic returning true/false on whether the field should be editable or not
  }
 </script>
  • Related