This is a migrated thread and some comments may be shown as answers.

Grid with batch editng enabled question

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PAUL
Top achievements
Rank 1
PAUL asked on 09 Nov 2012, 01:14 PM
I have a grid with batch editing enabled and have got it working very well. This particular gird deals with line items in an order.

So when the user clicks Add New item they enter the part number description and other pertinent info and click save. No problem.

The problem is that once we save the item, we do not want to have the part number field to be editable. If they need to change the part number they should have to delete the line item and add it again.

I am trying to figure out how to make this field not editable on the on edit event but can't figure it out. I have some java script for the edit event commented out in my code that was suppose to deal with another issue but it crashes. I know I am on the right path but can't take it in for the score. The java script I have commented out is in the next code block.

Any help is appreciated...
@(Html.Kendo().Grid<BuyItNow.Models.LineItemViewModel>().HtmlAttributes(htmlAttributes)
               .Name("kendoGrid")
               .EnableCustomBinding(true)
               .BindTo(Model.Data)
                .Events(events => events.DataBound("dataBound"))
                .Columns(columns =>
                {
                   columns.Bound(p => p.lineNumber);
                   columns.Bound(p => p.partNum).Title("Part#").EditorTemplateName("PartNumber");
                    columns.Bound(p => p.partDescription).EditorTemplateName("Description");
                    columns.Bound(p => p.unitOM).EditorTemplateName("UOM").Equals("EA");
                    columns.Bound(p => p.partQuant).EditorTemplateName("Number").Format("{0:n0}");
 })
 
                .ToolBar(toolbar =>
                {
                    toolbar.Create();
                    toolbar.Save();
                })
     .Editable(editable => editable.Mode(GridEditMode.InCell))
 
     .Pageable()
     .Sortable()
        // .Scrollable()
     .Navigatable()
     .DataSource(dataSource => dataSource
         .Ajax()
         .Total(Model.Total)
          .Batch(true)
          .ServerOperation(false)
         .Events(events => events.Error("error_handler"))
 
         .Model(model =>
         {
             model.Id(p => p.itemID);
              
             model.Field(p => p.lineNumber).Editable(false).DefaultValue("0000");
           
         })
 
 
            .Create(update => update.Action("_Create", "LineItems"))
            .Read(read => read.Action("_Read", "LineItems"))
            .Update(update => update.Action("_Update", "LineItems"))
         
)
 
.Resizable(resize => resize.Columns(true))

$(document).ready(function() {
                var grid = $("#kendoGrid").data("kendogrid");
                 // bind to the edit event
                grid.bind("edit", function (e) {
                    debugger;
                    e.preventDefault();
                    e.container.find('input:last').focus()
                    }
        });

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 13 Nov 2012, 12:47 PM
Hi Paul,

Basically this is not supported out-of-the-box, however you should use the Edit event of the Grid to hide the desired column editor when editing existing records. Please check the example below of Grid using Inline editing mode:

edit: function (e)
{
    //check if current record is newly created
    if(e.model.ProductID != null)
    {
        // get a reference to the grid widget
        var grid = $("#grid").data("kendoGrid");
  
        //select the column by index and remove the editor
        $(".k-grid-edit-row td:nth-child(3)").html("");
    }
},
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
PAUL
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or