Save the processed information in a Kendo Grid column

I am attempting to store data in a specific column by calculating it using information from another column.

Currently, I have a function that retrieves the number of available licenses for a given Id in JSON format:

function getAvailableLicenses(id) {
    var url = "/Host/Organization/AvailableLicenses/" + id;
    $.get(url, function (data) {
        return data.AvailableLicenses;
    });
}

How can I save this number in a column named "AvailableLicenses"?

Here is my current Grid setup:

$("#OrganizationGrid").kendoGrid({
dataSource: viewModel.get("orgDataSource"),
filterable: {
    extra: false
},
sortable: true,
pageable: true,
columns: [
    { field: "Id", hidden: true },
    { field: "Name", template: "<a href='/Host/Organization/Detail/#:Id#'>#:Name#</a>" },
    { field: "LicenseNumber", title: "Number of Licenses" },
    { field: null, title: "Available Licenses", template: "#= getAvailableLicenses(Id) #" },
    { field: "LicenseExpiration", title: "License Expiration", format: "{0:MM/dd/yyyy}" },
    { field: "State" },
    { field: "Active" }
],
editable: false
});

Although the function is being called for all rows, the "AvailableLicenses" column displays "Undefined". Am I missing something here?

Answer №1

In my opinion, the most effective approach is to utilize the dataSource parse() function.

To begin, your column configuration should be updated as follows:

 { field: "AvalableLicenses", title: "Available Licenses" },

You can always make use of your own template.

Furthermore, within your dataSource(), consider adding the following code snippet:

schema: {
    parse: function(response) {
      for (var i = 0; i < response.length; i++) {
       response[i].AvalableLicenses= null;
       response[i].AvalableLicenses = getAvailableLicenses(response[i].Id)
      }
      return response;
    }
  }

UPDATE:

If you prefer sticking with your current method, there may be an issue with your configuration, possibly resulting in the $.get returning undefined or unexpected values. For reference, I have provided a working example.

http://jsfiddle.net/jwocf897/

I hope this information proves useful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Ajax and jQuery to extract information from an XML file based on an identification number

Currently, I am looking for a way to showcase a specific product with its description from my XML file by using the product's ID. The structure of my XML file is shown below: https://i.sstatic.net/wFWgW.png Below is the JavaScript code I am using: ...

How can I conceal child <div> elements when the parent div is resized?

Struggling to implement a zoom in/out feature on my web app using the jqueryUI slider. Having trouble handling cases where the parent div shrinks too much, causing issues with the child containers. <div class="puck originator inline-block" style="w ...

Uncovering the Depths of React Native Background Services

While using Firebase, I want my app to push notifications when new data is added to the database while it's in the background. Currently, I've implemented the following code: message.on('child_added', function(data) { pushNotificatio ...

Execute the component function located within one page using another page

Can someone help me understand how to trigger OnSwipe from inside a different JS file named CardFooter.js? This file contains a button with an OnClick event that triggers OnSwipe from the preceding JS file called CardItem.js. Both of these files are includ ...

Update the $_Get value without the need to refresh the entire page

I have a directory named vehicles, containing approximately 600 distinct images, all with the extension (.jpg), and each named as numbers from 1 to 600. I am displaying them as a vehicle gallery with Next and Previous buttons. The image displayed is deter ...

jQuery .css Intervals

Recently, I came across a code snippet that adjusts the .css value of a div $("#1").mouseover(function () { $("#naam").css('visibility', 'visible'); }); I'm looking to add a specific interval of time to this ...

Generating thick, shadowed lines in three.js to represent layers in a 3D printing visualization

I've been exploring ways to add depth to lines in Three.js that can cast shadows and appear as solid objects, but so far I've only achieved thicker lines that lack the 3D look I'm aiming for. This is for an online 3D printing platform where ...

When attempting to click on another button, the action does not seem to be working as expected. The button in question has a

Greetings! I have encountered an issue where both of my buttons work perfectly fine individually, but when I attempt to use Button A to click Button B using JavaScript, it doesn't seem to work. I can confirm that Button A functions correctly as the al ...

"Modifying the image path using Jquery does not seem to

I'm working with a jquery ajax carousel and trying to modify the path, but for some reason, it's not updating. Can anyone offer some assistance? Below is the jquery code snippet: $(document).ready(function () { var dir = "../images/big-carous ...

Enhance and modify data with AngularJS, while also incorporating new information into the

Working on a feature where Worklists can be added and edited or deleted from local storage. Encountering an issue where after editing a worklist, it cannot be added anymore as it updates the existing worklist data that was selected for editing. (the edite ...

Tips for preventing conflicts between variables and functions in JavaScript (no need for a jQuery plugin)

How can I prevent variable and function conflicts in Javascript without relying on jQuery plugins? I am interested in creating my own functions but want to avoid conflicts. I believe using function scope, where functions are used solely for the purpose of ...

Angular button will be disabled if the form control is empty

Is there a way to deactivate the search button when the text box is empty? I attempted to use the "disabled" attribute on the search button, but it didn't work. Here is my HTML code: <div class="col-md-5 pl-0"> <div class="in ...

Limiting the display to only a portion of the document in Monaco Editor

Is there a way to display only a specific portion of a document, or in the case of Monaco, a model, while still maintaining intellisense for the entire document? I am looking to enable users to edit only certain sections of a document, yet still have acce ...

Utilize AdWords Scripts/Javascript to display array objects on separate rows within a spreadsheet

I am currently facing some difficulties in figuring out how to display objects from an Array on separate rows within a spreadsheet using Google AdWords. var SPREADSHEET_URL = "xxxx"; function main(){ var spreadsheet = SpreadsheetApp.openByUrl(SPREADSH ...

Implementing jQuery form validator post anti-SPAM verification?

I am facing what seems like a straightforward JavaScript issue, but my knowledge in this area is still limited. Following a successful implementation of basic anti-SPAM feature that asks the user to solve a simple math problem, how can I integrate jQuery& ...

The JavaScript slideshow fails to display an image during one rotation

The slideshow displays a sequence of images from pic1.jpg to pic8.jpg, followed by a 4-second pause with no image, and then repeats starting again at pic1.jpg. I am looking to have it loop back to pic1.jpg immediately after displaying pic8.jpg. Below is t ...

What steps should I take to resolve the "undefined property match cannot be read" error that's showing up in this code?

Currently, I am facing an issue while attempting to integrate the nativescript-imagepicker plugin into my Nativescript App. I keep receiving an error message stating **cannot read **property match of undefined**. Below is a summary of the steps I have take ...

How to eliminate quotation marks from a nested array in JavaScript

Is there a way to eliminate double quotes from nested array information? ["[a,b,c],[b,c,d],[e,f,g]"] Transforming it into this array: [[a,b,c],[b,c,d],[e,f,g]] through the utilization of javascript ...

Exploring the capabilities of storing and retrieving nested objects within a React database

I'm having trouble retrieving nested items from my database. This is how my database is structured: GET /dwelling/room/ [ { "room_id": 1, "room_name": "Living Room", "room_data": [ { "id": 1, ...

Struggling to make antd compatible with my create-react-app project

Exploring ant.design with create-react-app piqued my interest, so I decided to follow the steps outlined in the antd documentation. https://ant.design/docs/react/use-with-create-react-app npx create-react-app antd-demo npm add antd Within the app.js fil ...