kendo ui Editable color input field on grid

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

As you can see in the code below, i have a grid with editable cells. At the column named "szin" i tired to implement a kendo colorpicker and it works just fine. My problem is, that the colors are only displayed when you try to edit one of the cell. Can i make it permanently displayed somehow? I dont care if the bg-color of the cell change or the dropdown box visible all the time or with any other methods.

Here's my code:

<!DOCTYPE html> <html> <head>     <link href="../styles/kendo.metro.min.css" rel="stylesheet">     <link href="../styles/kendo.common.min.css" rel="stylesheet">     <script src="../js/jquery.min.js"></script>     <script src="../js/kendo.all.min.js"></script> </head> <body>     <div id="grid" style="width:1024px; height:400px; margin-left:auto; margin-right:auto;"></div>     <script>         $(document).ready(function() {             $("#grid").kendoGrid({                 dataSource: {                     transport: {                         read: "load.php",                         update: {                             url: "load.php",                             type: "POST"                          }/*,                         destroy: {                             url: "load.php",                             type: "DELETE"                         }*/                      },                     error: function(e) {                         alert(e.responseText);                     }                 },                 columns: [  { field: "termekid", width:"70px" },                             /*                             ...                             */                             { field: "szin", width:"74px",                                 editor: szinColorPickerEditor                             }                             /*                             ...                             */                          ],                 sortable: true,                 editable: true,                 navigatable: true,                 toolbar: ["save", "cancel"/*, "create"*/],                 pageable: {                         previousNext: true,                         numeric: true,                         buttonCount: 5,                         input: false,                         pageSizes: [0, 10, 20, 50, 100],                         refresh: true,                         info: true                       }              });              function szinColorPickerEditor(container, options) {                 $("<input type='color' data-bind='value:" + options.field + "' />")                     .appendTo(container)                     .kendoColorPicker({                         buttons: true                      });              }           });      </script> </body> </html> 

回答1:

You can use a column template for this, for example you could change your field definition to:

{     field: "szin",     width: "74px",     editor: szinColorPickerEditor,     template: "<span style='display: inline-block; width: 100%; height: 100%; background-color: #= szin #'></span>" } 

See demo



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!