Kendo UI grid dropdown and angular


Dalton 5

I try to set custom dropdown menu in Kendo UI.

I have mentioned my problem.

http://dojo.telerik.com/aFIZa/13

My problem is that I don't know how to set the selected text in the template property? I want to display the text field but save the ID as a value. And I don't want to use external data source. I want it to be inline in json.

code show as below:

 $scope.mainGridOptions = {
    dataSource: $scope.dataSource,
    pageable: true,
    height: 550,
    toolbar: ["create"],
    columns: [

      { field: "Category", title: "Category", width: "180px", 
       editor: function(container, options) {
    var editor = $('<input kendo-drop-down-list required k-data-text-field="\'cat\'" k-data-value-field="\'id\'" k-data-source="{data:[{id: 1, cat: \'test\'}, {id: 2, cat: \'test2\'}]}" data-bind="value:Category"/>')
    .appendTo(container);

    $compile(editor)($scope);
    editor.css("visibility", "visible");
       }

         , template:"selected text in the combo "
      }
  ], editable: true


}
don't vote

Ok, this is tough, but I think I can achieve what you want, or at least I can get close:

$scope.mainGridOptions = 
{
    dataSource: $scope.dataSource,
    pageable: true,
    height: 550,
    toolbar: ["create"],
    columns: [
    { 
        field: "Category", title: "Category", width: "180px", 
        editor: function(container, options) 
        {
            // #1
            var editor = $('<input kendo-drop-down-list required k-data-text-field="\'cat\'" k-data-value-field="\'id\'" k-data-source="{data:[{id: 1, cat: \'test\'}, {id: 2, cat: \'test2\'}]}" data-bind="value:Category,events:{ change: onChange }"/>')
            .appendTo(container);

            $compile(editor)($scope);
            editor.css("visibility", "visible");
        }, 

        // #2
        template:kendo.template($("#column-template").html())
    }], 
    editable: true,

    // #3
    edit: function(e) 
    {
        var ko = kendo.observable(
        {
            onChange: function(e) 
            {
                var el = $(e.sender.element);
                var ddl = el.data("kendoDropDownList");
                var ds = $scope.dataSource.getByUid(el.closest("tr").data("uid"));

                ds.OptionText = ddl.text();
            },
        });

        var widget = $(e.container).find("input");
        kendo.bind(widget, ko);
    }
}});

demo .

In the code, you can notice 3 changes:

  1. data-bind="value:Category,events:{ change: onChange }"It looks like I'm adding an object eventsto the binding , which I declare onChangeas an event handler. We will discuss this in the third item below;change

  2. For complex templates (with javascript code and logic) I create script content and render it at that templateproperty . The template is like this:

    <script id="column-template" type="text/x-kendo-template">
        # if (data.hasOwnProperty('OptionText')) { #
        #: OptionText #
        # } else { #
        #: "selected text in the combo" #
        # } #
    </script>
    

    In the template I just check the property OptionTextin the model (the current item of the datasource) and then: if it exists, use it; otherwise, use the default text. We will OptionTextdiscuss in the third item below;

  3. Now, here I add an event editto the grid . In that case I created an object in which the function handler was defined. In that function, I look for the current dataSource( ) and add the text of the selected item in the dropdown within it, as an attribute , which is used in the above template.observableonChangedsOptionText

I hope this explains how it works (actually, I hate using those binders and observables, but need them sometimes).

good luck.

Related


Kendo UI grid dropdown and angular

Dalton 5 I try to set custom dropdown menu in Kendo UI. I have mentioned my problem. http://dojo.telerik.com/aFIZa/13 My problem is that I don't know how to set the selected text in the template property? I want to display the text field but save the ID as a v

Kendo UI grid dropdown with foreign keys

lucky I should have asked this question on the Telerik forums, but after going through many answers, kudos to Telerik, I think it's futile, and I'm hoping for a better and faster answer here. So here I am: I'm using the Kendo UI Grid control and displaying the

How to filter Kendo UI MVC grid with dropdown

Sofinia I have a kendo grid that filters by pushing values from a dropdown into a built in kendo filter. The grid can be searched in the same way when typing a value in a text box and searching. Here is my kendo grid and dropdown menu @(Html.Kendo().DropDownL

Kendo ui grid dropdown editor not loading data

Leonid Radkevich Unable to load data to Kendo dropdown. It fetches data from backend but the list is empty. The backend looks like: [HttpPost] public ActionResult GetCities(DataSourceRequest command) { var cityModel = _uow.Cities.GetAll().T

Kendo ui grid dropdown editor not loading data

Leonid Radkevich Unable to load data to Kendo dropdown. It fetches data from backend but the list is empty. The backend looks like: [HttpPost] public ActionResult GetCities(DataSourceRequest command) { var cityModel = _uow.Cities.GetAll().T

DropDown popup width (Telerik: Kendo UI for Angular)

Macla How can I set the DropDown popup width to auto so all text is visible? I want to keep a smaller width for the widget but a larger width for the popup. renew: Link to Plunkr . import { Component } from '@angular/core'; @Component({ selector: 'my-app',

DropDown popup width (Telerik: Kendo UI for Angular)

Macla How can I set the DropDown popup width to auto so all text is visible? I want to keep a smaller width for the widget but a larger width for the popup. renew: Link to Plunkr . import { Component } from '@angular/core'; @Component({ selector: 'my-app',

DropDown popup width (Telerik: Kendo UI for Angular)

Macla How can I set the DropDown popup width to auto so all text is visible? I want to keep a smaller width for the widget but a larger width for the popup. renew: Link to Plunkr . import { Component } from '@angular/core'; @Component({ selector: 'my-app',

DropDown popup width (Telerik: Kendo UI for Angular)

Macla How can I set the DropDown popup width to auto so all text is visible? I want to keep a smaller width for the widget but a larger width for the popup. renew: Link to Plunkr . import { Component } from '@angular/core'; @Component({ selector: 'my-app',

DropDown popup width (Telerik: Kendo UI for Angular)

Macla How can I set the DropDown popup width to auto so all text is visible? I want to keep a smaller width for the widget but a larger width for the popup. renew: Link to Plunkr . import { Component } from '@angular/core'; @Component({ selector: 'my-app',

Kendo UI for Angular custom sorting grid columns

h3li0s I have the following column in Kendo Grid (Jquery's UI) which has a special sorting method based on customer needs. field: "daysLeft", title: "Accessible", width: 130, sortable: { compare: function (a, b, descending) { if (a.daysLeft == 'Not start

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Dynamically create grid for Angular in Kendo UI

ps0604 Kendo UI for Angular has a grid that can be defined as follows: <kendo-grid [data]="gridData" [height]="410"> <kendo-grid-column field="ProductID" title="ID" width="40"> </kendo-grid-column> <kendo-grid-column field="

Dynamically create grid for Angular in Kendo UI

ps0604 Kendo UI for Angular has a grid that can be defined as follows: <kendo-grid [data]="gridData" [height]="410"> <kendo-grid-column field="ProductID" title="ID" width="40"> </kendo-grid-column> <kendo-grid-column field="

Kendo UI for Angular custom sorting grid columns

h3li0s I have the following column in Kendo Grid (Jquery's UI) which has a special sorting method based on customer needs. field: "daysLeft", title: "Accessible", width: 130, sortable: { compare: function (a, b, descending) { if (a.daysLeft == 'Not start

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo Angular Grid Filter for UI Values

fanaticism I'm using Angular 7's Kendo UI and filtering works most of the time, but I can't figure out one thing. I have some fields that are piped to make the UI more user friendly. For example, I have a code in my object that specifies a software. When it's

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI for Angular custom sorting grid columns

h3li0s I have the following column in Kendo Grid (Jquery's UI) which has a special sorting method based on customer needs. field: "daysLeft", title: "Accessible", width: 130, sortable: { compare: function (a, b, descending) { if (a.daysLeft == 'Not start

Dynamically create grid for Angular in Kendo UI

ps0604 Kendo UI for Angular has a grid that can be defined as follows: <kendo-grid [data]="gridData" [height]="410"> <kendo-grid-column field="ProductID" title="ID" width="40"> </kendo-grid-column> <kendo-grid-column field="

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder

Kendo UI Grid for Angular to dynamically reorder columns

Exquisite I have a Kendo UI for Angular and not one for JQuery, and I've been trying to see how to reorder the columns dynamically. The API allows enabling it by reordering like this: <kendo-grid [reorderable]="true"...../> But I want tp to be able to reorder