最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable the row in the kendo grid based on condition - Stack Overflow

programmeradmin3浏览0评论

I have a Kendo grid in which I have a checkbox in the last column and I am binding this grid from the server side(filling the data from the server) and in that the checkbox value is also ing from the server.I want to disable the entire row in which the checkbox value is true i.e it is checked and want to allow the editing when the checkbox value is false i.e it is not checked. My code as follows:

@(Html.Kendo().Grid(Model)
    .Name("UpdatedHeadGrid")
        .Columns(columns =>
        {
           columns.Bound(p => p.ID).Hidden(true).ClientTemplate("#= ID#" + "<input type='hidden' class='ID'  value='#=ID#' />").Width(10);
           columns.Bound(p => p.IsAllocated).HeaderHtmlAttributes(new { title = "Allocatable" }).Title("Allocatable").ClientTemplate("<input type='checkbox'  ${ IsAllocated == true ? checked='checked' : ''}   class='IsAllocated' value='#=data.IsAllocated#' style='width:50px;' />").Width(50).HtmlAttributes(new { style = "text-align: center;vertical-align: middle;"});
           columns.Bound(p => p.Total).HeaderHtmlAttributes(new { title = "Total Amount" }).Title("Total").ClientTemplate("<input type='text' disabled='disabled' class='Total' value='#=data.Total#' style='width:65px;' />").Width(60).HtmlAttributes(new { style = "text-align:right", onclick = "DisableEdit(this)" });
           .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Events(e =>
    {
       e.DataBound("onRowBound");

       e.Edit("onEdit");
    })     
    .PageSize(15)
    .Resizable(resize => resize.Columns(true)) 
)

For this i have written the edit function i.e onEdit function as follows:

<script>
    function onEdit(e) {
        var fieldName12548 = e.container.find('input[type="checkbox"][name="IsAllocated"]').attr("value");
        if (fieldName12548 === "Total") {
            this.closeCell();
        }
    }
</script>

Here Instead of only the column with the fieldname="Total" i have to disable all the row.

For editing more than one column

var fieldName = e.container.find("input").attr("name");
  if (fieldName === "AccountTransactionItemDescription" && fieldName === "Identifier" && fieldName === "TradeOrNonTrade" && fieldName === "EntityName")
   {
     this.closeCell();
   }

but here It not working may be this can refer only one.So what would be solution for this?

I have a Kendo grid in which I have a checkbox in the last column and I am binding this grid from the server side(filling the data from the server) and in that the checkbox value is also ing from the server.I want to disable the entire row in which the checkbox value is true i.e it is checked and want to allow the editing when the checkbox value is false i.e it is not checked. My code as follows:

@(Html.Kendo().Grid(Model)
    .Name("UpdatedHeadGrid")
        .Columns(columns =>
        {
           columns.Bound(p => p.ID).Hidden(true).ClientTemplate("#= ID#" + "<input type='hidden' class='ID'  value='#=ID#' />").Width(10);
           columns.Bound(p => p.IsAllocated).HeaderHtmlAttributes(new { title = "Allocatable" }).Title("Allocatable").ClientTemplate("<input type='checkbox'  ${ IsAllocated == true ? checked='checked' : ''}   class='IsAllocated' value='#=data.IsAllocated#' style='width:50px;' />").Width(50).HtmlAttributes(new { style = "text-align: center;vertical-align: middle;"});
           columns.Bound(p => p.Total).HeaderHtmlAttributes(new { title = "Total Amount" }).Title("Total").ClientTemplate("<input type='text' disabled='disabled' class='Total' value='#=data.Total#' style='width:65px;' />").Width(60).HtmlAttributes(new { style = "text-align:right", onclick = "DisableEdit(this)" });
           .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Events(e =>
    {
       e.DataBound("onRowBound");

       e.Edit("onEdit");
    })     
    .PageSize(15)
    .Resizable(resize => resize.Columns(true)) 
)

For this i have written the edit function i.e onEdit function as follows:

<script>
    function onEdit(e) {
        var fieldName12548 = e.container.find('input[type="checkbox"][name="IsAllocated"]').attr("value");
        if (fieldName12548 === "Total") {
            this.closeCell();
        }
    }
</script>

Here Instead of only the column with the fieldname="Total" i have to disable all the row.

For editing more than one column

var fieldName = e.container.find("input").attr("name");
  if (fieldName === "AccountTransactionItemDescription" && fieldName === "Identifier" && fieldName === "TradeOrNonTrade" && fieldName === "EntityName")
   {
     this.closeCell();
   }

but here It not working may be this can refer only one.So what would be solution for this?

Share Improve this question edited Aug 18, 2014 at 6:16 SantyEssac asked Aug 13, 2014 at 9:18 SantyEssacSantyEssac 8093 gold badges20 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Instead of using jQuery for finding the value of the input, I would suggest you to use model a field of the event handler argument e.

So you should do:

<script>
    function onEdit(e) {
        if (e.model.IsAllocated) {
            this.closeCell();
        }
    }
</script>

See it in action here: http://jsfiddle/OnaBai/ry82wcvc/

发布评论

评论列表(0)

  1. 暂无评论