binding to GUID on DataValue field

2 posts, 1 answers
  1. newKendoUser
    newKendoUser avatar
    10 posts
    Member since:
    Oct 2017

    Posted 31 Jan Link to this post

    Hi,

     

    I have a Kendo Drop down, displaying remote data (of type odata) implemented as follows:

     

        $("#listDropDown").kendoDropDownList({
            filter: "contains",
            dataTextField: "displayName",
            dataValueField: "fieldid",
            optionLabel: "Please Select..."
            dataSource: {
                type: "odata-v4",
                transport: {
                    read: function (options) {
                        $.ajax({
                            url: someURL,
                            dataType: "json",
                            success: function (result) {
                                options.success(result);
                            },
                            error: function (result) {
                                console.log(result);
                            }
                        });
                    }
                } 
            }
        });

    the 'fieldId' in this case is of type GUID. The drop down is created successfully and displaying data on screen. Using the no data template i can also successfully add a new item and refresh the drop down to the item is available on the list. 

     

    I would like to dynamically set the selecteditem on the drop to the item that has just been added. I am using the following code. 

     

     $("#listDropDown").data("kendoDropDownList").value(newFieldId);

     

    'newfieldId' is a GUID that has been returned by the ajax call which has just created the new item. This is getting a value successfully, however doesnt appear to work. I have also tried hard coding this to use a value which i know existsin the drop down which i pass in as a string as i would expect a GUID to and this still doesnt work. This leads me to believe i havent configured my drop down correctly for using the GUID as the datavalue field. 

     

    Can you confirm if this is the case?

     

    Many thanks

  2. Answer
    Neli
    Admin
    Neli avatar
    221 posts

    Posted 02 Feb Link to this post

    Hi Martina,

    In order to set the selected item in the DropDownList you can use the select() method.
    As you can see in the 'Add New Item' demo, this method is used, so after a new item is added to the DropDownList, it is also set as a currently selected item
    dataSource.one("sync", function() {
         widget.select(dataSource.view().length - 1);
     });

    You should be able to select the item with the value() method as well. Enclosed you will find an example where the item is selected by using the value method:
    dataSource.one("sync", function(e) {                 
    var lastIndex = e.sender.data().length - 1;
    var last = e.sender.data()[lastIndex];
    widget.value(last.ProductID);
    });

    Could you please let us know if you are using the same approach as in the provided example? May I ask you to modify the example in order to replicate the issue the way it is at your end?This will help us to inspect it locally and provide further assistance.

    I hope this information helps.

    Regards,
    Neli
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top