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

Enable grid row edit depending on field value

6 Answers 237 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jeff
Top achievements
Rank 1
jeff asked on 29 Jun 2015, 05:56 PM

Hi!

So I know I can do this for inline editing, a cell at a time, for example:

edit : function (e) {
        var data = e.model;
        if (data.City === "Detroit") {
           this.closeCell();
        }
        e.preventDefault();
    },

..but if I'm using popup editing, could I disable editing depending on value?

Is there a 'closeRow()' equivalent or anything like that?

Thank you!

 

6 Answers, 1 is accepted

Sort by
0
jeff
Top achievements
Rank 1
answered on 29 Jun 2015, 07:40 PM

I found cancelRow() but...

 

edit: function (e) {
     var data = e.model;
     if (data.Status == "Optional" || data.Status == null) {
        e.preventDefault();
     } else if (data.Status != "Optional") {
         this.cancelRow();
     }
 },

It's also killing the Create Row button as well... any ideas here?

 Thank you!

0
Dimiter Madjarov
Telerik team
answered on 30 Jun 2015, 08:28 AM

Hello Jeff,

If you would like to distinguish the create and update operations in the edit event handler, you should use the isNew() method of the model.
E.g.

edit: function (e) {
   if(e.model.isNew()) {
      // operation is create
   } else {
      // operation is update
   }
}

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
jeff
Top achievements
Rank 1
answered on 30 Jun 2015, 06:30 PM

I retract my answer! :)

 

edit: function (e) {
   if(e.model.isNew()) {
     alert('ahem!');
  } else {
    var data = e.model;
    if (data.Status == "Approved") {
        this.cancelRow();
    } else {
        e.preventDefault();
    }
   }
},

Am I missing something here? I'll try it in a dojo as well...

Thank you!

0
jeff
Top achievements
Rank 1
answered on 30 Jun 2015, 08:05 PM

Visually, that's pretty rough; instead, can you suggest a method for hiding the edit button on rows that possess specific criteria, something like:

var data = e.model;
  if (data.Status == "Approved") {
    $('.k-button .k-button-icontext .k-grid-edit').style.visibility="hidden";
  } else {
    e.preventDefault();
  }

Thank you very much!

 

0
jeff
Top achievements
Rank 1
answered on 30 Jun 2015, 10:21 PM

A more literal translation, what I'm thinking, is something in dataBound(), like this:

$("#grid tbody tr .k-grid-edit").each(function () {
    var currentDataItem = $("#grid").data("kendoGrid").dataItem($(this).closest("tr"));
    var data = e.model;
    if (currentDataItem.isEditable == true && data.Status == "Approved" || currentDataItem.isEditable == true && data.Thing == "OK") {
        $(this).remove();
    }
});
 

but this isn't quite doing it; I'm not sure if I'm calling to the fields in the row correctly; any ideas?

Again, thank you very much!

 

 

0
Accepted
Dimiter Madjarov
Telerik team
answered on 01 Jul 2015, 12:03 PM

Hello Jeff,

Using the dataBound event handler is the correct place to achieve the task. Here is a sample implementation, in which I am removing the edit button for specific rows.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
jeff
Top achievements
Rank 1
Answers by
jeff
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or