can add if condition inside column while describing columns of grid? whats wrong in code
want display 1 button in grid under column ,if length of text exceeds more 40char. trying put if condition if content/data less 40 char display content else display button , on click of button open pop-up display complete content inside pop-up? how can put command conditionally display button?
here code
columns: [{ field: "id", title: "id", width: "100px" }, // fields in grid { field: "name", title: "name", width: "100px" }, { field: "remarks", title: "remarks", width: "160px", // under column button displayed in each var length = 40; if (data.remarks.length > length) { //here condition seems wrong, there other way display button condition command: { name: "remarks", text: "remarks", click: function (e) { var tr = $(e.target).closest("tr"); var data = this.dataitem(tr); var win = $('#remarkswindow'); win.html(data.remarks); if (!win.data('kendowindow')) { win.kendowindow({ width: '600px', height: '200px', title: 'remarks', actions: ['close'] }); } win.parent().css({ top: e.pagey - 50, left: e.clientx - 640, width: '600px', height: '200px' }); win.data('kendowindow').open(); // open pop-up contains data return false; } } } } },
first of all, have syntax error in javascript. note can't put statements or declarations between properties of object:
var obj = { a: 1, if (true) { b: 2; } } or
var obj = { a: 1, var b = 1; } the examples above doesn't works. in column property have use template property:
{ field: "remarks", title: "remarks", width: "160px", template: "" // <- here goes logic } so simple template can set string containing html javascript logic, e.g.:
# if (remarks.length > 40) { # <input type='button' class='btn-remarks' /> # } # yes, have set button html yourself. there no way add condition command button(and shame, actually).
you can check how template works here.
then column item should be:
{ field: "remarks", title: "remarks", width: "160px", template: "# if (remarks.length > 40) { # <input type='button' class='remarks' /> # } #" } then have set event buttons(probably in databound event):
$("#yourgrid").on("click", ".btn-remarks", function() { // click logic here }); give try , tell me happens.
Comments
Post a Comment