jquery - Kendo Grid : disable row edit -


i have editable grid , want make rows non editable depending on conditions.

can please advice how can this.

thanks

out of box, there no feature allows controlling edition per row based. can exit edition when row tried edit.

there 1 event edit fired once cell enters in edition mode. can close cell detect conditions true.

example: have grid following schema definition:

schema  : {     model: {         fields: {             id       : { type: 'number' },             firstname: { type: 'string' },             lastname : { type: 'string' },             city     : { type: 'string' }         }     } } 

and don't want allow edition of rows city seattle. edit handler should defined as:

var grid = $("#grid").kendogrid({     datasource: ds,     editable  : true,     edit      : function (e) {        // e.model contains model corresponding row being edited.         var data = e.model;         if (data.city === "seattle") {             // close cell (exit edition mode)            this.closecell();         }         e.preventdefault();     },     pageable  : true,     columns   :             [                 { field: "firstname", width: 90, title: "first name" },                 { field: "lastname", width: 90, title: "last name" },                 { field: "city", width: 100 }             ] }).data("kendogrid"); 

the problem edit handler invoked after cell in edit mode closing might produce flickering in cases should work.

the second option define grid non-editable , invoke editcell manually if condition true:

in case define grid as:

var grid = $("#grid").kendogrid({     datasource: ds,     editable  : false,     pageable  : true,     columns   :             [                 { field: "firstname", width: 90, title: "first name" },                 { field: "lastname", width: 90, title: "last name" },                 { field: "city", width: 100 }             ] }).data("kendogrid"); 

and define click handler cells:

grid.tbody.on("click", "td", function (e) {     // close possible cell in edit mode     grid.closecell();     // find data corresponding clicked cell     var data = grid.dataitem($(e.target).closest("tr"));     // check condition     if (data.city !== "seattle") {         // enter edition mode         grid.editcell(e.target);     } }); 

where retrieve data row corresponding clicked table cell , check condition. if condition matches open cell.

despite not have flickering, not preferred because need trigger save saving cells , despite grid not editable, editing it.

running example first implementation here : http://jsfiddle.net/onabai/nww7t/ , second here: http://jsfiddle.net/onabai/nww7t/1/

for editions modes other "incell" easiest of implementing same functionality creating custom defined edition button controls if row should or should not go edition mode.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -