Kendo UI grid for Jquery - Filling data in to dropdown inside grid is not working.

1 Answer 16 Views
Grid
ravi
Top achievements
Rank 1
ravi asked on 15 Sep 2025, 08:51 PM

Hi,

I am experimenting with this grid control.

I have this code where I am filling a grid with data from the SQL table. The data is loading good.

Second step : I want to edit the row and in this case , I want to edit City column which will be a dropdown in edit mode. I have the code to pull the data from database. My API is returning cities. I can see it in console.log.  However, the dropdown in the edit mode does not show any data. It is blank. I am not sure where to fix it or how to fix it.

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
  <link href="https://kendo.cdn.telerik.com/themes/12.0.0/default/default-main.css" rel="stylesheet" />
  <!-- Add the Kendo library by either using the JAVASCRIPT MODULES -->
  <script src="https://kendo.cdn.telerik.com/2025.3.825/mjs/kendo.all.js" type="module"></script>

    <script src="telerik-license.js" type="text/javascript"></script>
  
  <div id="tripsGrid"></div>
  <script type="text/javascript" >
    $(document).ready(function() {
            $("#tripsGrid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "http://localhost:54243/api/Dispatch/GetTripsForSelectedDate", // Replace with your actual API endpoint
                            type: "GET",                  // <-- key change
                            dataType: "json",
                            contentType: "application/json"
                        },
                        parameterMap: function (options, type) {
                              if (type === "read") {
                                return kendo.stringify({
                                  page: options.page,
                                  pageSize: options.pageSize,
                                  sort: options.sort,
                                  filter: options.filter,
                                  date: $("#datePicker").val() || null  // if you have a date picker
                                });
                              }
                              // For create/update/destroy, send the model as JSON.
                              // If you enable batch: true later, handle options.models[0] instead.
                              if (type === "create" || type === "update" || type === "destroy") {
                                return kendo.stringify(options); // 'options' is the dataItem for non-batch
                              }
                            }
                         
                    },
                    schema: {
                        model: {
                            id: "Trip_ID",
                            fields: {
                                Trip_ID: { type: "number" },
                                Route: { type: "string" },
                                RouteID: { type: "number" },
                                Start_Dt: { type: "string", editable : true },
                                LastName: { type: "string",  editable : true },
                                FirstName: { type: "string",  editable : true },
                                StartDesc: { type: "string" },
                                StartAddr1: { type: "string" },
                                StartAddr2: { type: "number" },
                                StartCityID: { type: "number",  editable : true },
                                StartStateID: { type: "number",  editable : true },
                                StartZipID: { type: "number",  editable : true },
                                StartCity : { type: "string",  editable : true },
                                StartState: { type: "string" },
                                StartZip: { type: "string" }                               
                            }
                        }
                    },
                    pageSize: 10, // Optional: for client-side paging
                    serverPaging: true, // Set to true for server-side paging
                    serverSorting: true, // Set to true for server-side sorting
                    serverFiltering: true // Set to true for server-side filtering
                },
                height: 550,
                sortable: true,
                pageable: true,
                filterable: true,
                editable: { mode: "inline", confirmation: "Delete this trip?" },
                columns: [
                    { command: ["edit", "destroy"], title: "&nbsp;", width: 180 },
                    { field: "Trip_ID", title: "TripID" },
                    { field: "Route", title: "Route", format: "{0:c}" },
                    { field: "RouteID", title: "RouteID" },
                    { field: "Start_Dt", title: "Start Date" },
                    { field: "LastName", title: "Last Name" },
                    { field: "FirstName", title: "First Name" },
                    { field: "StartDesc", title: "Start Desc" },
                    { field: "StartAddr1", title: "Addr1" },
                    { field: "StartAddr2", title: "Addr2" },
                    { field: "StartCityID", title: "Start City ID", editor: startCityDropdownEditor, template: "#: StartCity #" },
                    { field: "StartStateID", title: "Start State ID" },
                    { field: "StartZipID", title: "Start Zip ID" },
                    { field: "StartCity", title: "StartCity", editor: startCityDropdownEditor, template: "#: StartCity #" },
                    { field: "StartState", title: "StartState" },
                    { field: "StartZip", title: "StartZipcode" }
                ]
            });
        });
        
        
        
        //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
        
        function startCityDropdownEditor(container, options) {
                      $('<input required name="' + options.field + '"/>')
                        .appendTo(container)
                        .kendoDropDownList({
                          optionLabel: "Select city...",
                          dataTextField: "LkupItem",
                          dataValueField: "LkupItemID",
                          valuePrimitive: true,          // model field is a number, not an object
                          filter: "contains",            // searchable
                          autoBind: true,
                          dataSource: {
                            transport: {
                              read: {
                                url: "http://localhost:54243/api/Dispatch/GetCities", // API below
                                type: "GET",                // keep POST to avoid 405/WebDAV issues
                                dataType: "json",
                                contentType: "application/json"
                              }
                            },
                            schema: { data: "data" } ,    // expect { data: [...] }
                             requestEnd: function(e) {
                              // log the raw response payload
                              console.log("API Response for GetCities:", e.response);

                              // log the parsed data that DropDownList will bind to
                              console.log("Parsed City List:", this.data());
                            }
                          },
                          change: function (e) {
                            // keep StartCity (name) in sync so the display template shows new text
                            var item = this.dataItem();
                            if (item && options.model) {
                              options.model.set("StartCity", item.LkupItem);
                            }
                          },
                          dataBound: function () {
                              // Ensure selected value shows when editing existing rows
                              if (options.model.StartCityID != null) {
                                this.value(options.model.StartCityID);
                              }
                            }
                        });
        }

        </script>
</asp:Content>

Thanks,

Ravi

Jay
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 17 Sep 2025, 02:30 PM

If you could convert your sample code to a dojo that demonstrates the issue, it'd probably be easier to give you more direct advice. That said, this stackoverflow post had a link to a dojo that seems to demonstrate what you're trying to do. I had to tweak it to use the current demo api, but hopefully that will give you a start to figure out the issue.

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 18 Sep 2025, 09:06 AM

Hello Ravi,

You mentioned: "My API is returning cities. I can see it in console.log. However, the dropdown is blank." This is most likely due to incorrect schema definition or incorrect property names (LkupItem and LkupItemID) not matching what your API actually returns.

- Check What Your API Actually Returns

In the browser console, find what http://localhost:54243/api/Dispatch/GetCities returns. It must be somethign like: 

[
  { "LkupItemID": 1, "LkupItem": "New York" },
  { "LkupItemID": 2, "LkupItem": "Los Angeles" }
]

- I noticed you are using the same function - startCityDropdownEditor - as editor for two different fields: StartCityID and StartCity. This is conceptually wrong and each field requires a separate editor.

Use the dropdown editor only on StartCityID, since it holds the selected value (ID).

{ field: "StartCityID", title: "Start City", editor: startCityDropdownEditor, template: "#: StartCity #" },

- Ensure dataTextField and dataValueField Match the API Fields

Your dropdown uses:

dataTextField: "LkupItem",
dataValueField: "LkupItemID"

Make sure these field names exactly match the keys in the API response. If the API returns CityName and CityID, update accordingly.

I hope this helps.

Regards,
Nikolay
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
ravi
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or