How to write a custom picker widget for a kendo ui grid?

888 Views Asked by At

I want to add a custom editor to a particular field in the kendo grid. The target cell must display a icon (similar to dropdown list),and on click i need a window/form popup below the trigger, containing form elements and a grid. Is it possible?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, it is possible. You can use the template option of the column to create an icon. Here is a complete demo:

  <div id="grid"></div>

  <div id="popup">
    <select data-bind="value: brand">
      <option>Mercedes</option>
      <option>BMW</option>
    </select>
    <button class="k-button" id="done">Done</button>
  </div>

  <script>
    $("#grid").kendoGrid({
      dataSource: {
        data: [
          { brand: "BMW" }
        ]
      },
      columns: [
        { field: "brand" },
        { 
          template: '<button class="k-button" onclick="edit(\'#= uid #\')">Change brand</button>'
        }
      ]
    });

    $("#popup").kendoWindow({
      visible: false
    }).on("click", "#done", function() {
      var popup = $("#popup").data("kendoWindow");
      popup.close();
    });

    function edit(uid) {
      var grid = $("#grid").data("kendoGrid");
      var dataItem = grid.dataSource.getByUid(uid);

      kendo.bind("#popup", dataItem);

      var popup = $("#popup").data("kendoWindow");
      popup.center().open();
      var popup = $("#popup").data("kendoWindow");
      popup.center().open();
    }

  </script>