How to automatically update checkbox status in Kendo UI Treeview when connected to a local dataset

A JavaScript object I'm working with contains an items array that defines a hierarchy. When I use this data to create a kendoTreeView widget and set loadOnDemand to false, the checkboxes that are supposed to be indeterminate appear unchecked instead.

To resolve this issue, I had to change the loadOnDemand setting to true, expand all nodes, and then collapse them again.

The reason for expanding and collapsing is because I need to interact with the leaf nodes of the tree based on user actions.

Is there a method to achieve the desired result with loadOnDemand set as false?

Answer №1

<!DOCTYPE html>
<html>
  <head>
    <base href="http://demos.telerik.com/kendo-ui/treeview/local-data-binding">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1028/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1028/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.1028/styles/kendo.material.mobile.min.css" />

    <script src="//kendo.cdn.telerik.com/2016.3.1028/js/jquery.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.3.1028/js/kendo.all.min.js"></script>
  </head>
  <body>
    <div id="example">

      <div class="demo-section k-content">
        <h4>Inline data (default settings)</h4>
        <div id="treeview-left"></div>
      </div>


      <script>
        var inlineDefault = new kendo.data.HierarchicalDataSource({                      
          data: [{

            "Name": "Test",
            "enabled": true,
            "text": "Test",
            "id": "Test",
            "Description": null,
            "Key": null,
            "items": [{
              "Name": "Workspace",
              "enabled": true,
              "text": "Workspace",
              "id": "Workspace",
              "Description": null,
              "Key": null,
              "items": [],
              "checked": true,
              "expanded": true
            },
                      {
                        "Name": "Deploy",
                        "enabled": true,
                        "text": "Deploy",
                        "id": "Deploy",
                        "Description": null,
                        "Key": null,
                        "items": [{
                          "Name": "Test.Deploy.Application",
                          "enabled": true,
                          "text": "Application",
                          "id": "Test.Deploy.Application",
                          "Description": "",
                          "Key": "Test.Deploy.Application",
                          "items": [],
                          "checked": false,
                          "expanded": true
                        },
                                  {
                                    "Name": "Test.Deploy.Visualization",
                                    "enabled": true,
                                    "text": "Visualization",
                                    "id": "Test.Deploy.Visualization",
                                    "Description": "",
                                    "Key": "Test.Deploy.Visualization",
                                    "items": [],
                                    "checked": true,
                                    "expanded": true
                                  },
                                  {
                                    "Name": "Test.Deploy.Application Workspace",
                                    "enabled": true,
                                    "text": "Application Workspace",
                                    "id": "Test.Deploy.Application Workspace",
                                    "Description": "",
                                    "Key": "Test.Deploy.Application Workspace",
                                    "items": [],
                                    "checked": false,
                                    "expanded": true
                                  }],
                        "checked": null,
                        "expanded": true
                      }],
            "checked": null,
            "expanded": true
          }]

        });

        $("#treeview-left").kendoTreeView({
          dataSource: inlineDefault,
          checkboxes: {
            checkChildren: true,
          },
          loanOnDemant:false,
        });


      </script>
    </div>


  </body>
</html>

It worked perfectly for my needs! For more information

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

Transforming instance of a Class into Json format for WebService

My goal is to retrieve an object of the Product class as a Json for a webservice. Despite successfully loading all the values into the object, I encounter an error when trying to return it as Json. Below is my method: <AllowAnonymous> <HttpGet&g ...

Encountering a problem while trying to run npm publish with public access, error code E

I've encountered an issue when attempting to publish a scoped package on npm, where I consistently receive this error via the CLI: npm ERR! code E403 npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@username%2fdynamic-ui-elements - Forbidd ...

What is the best way to have an image trail another in JavaScript coding for my game?

Hey, can someone help me create a zombie game where a zombie image moves towards a player image (zs.png) at a specific speed and decreases the player's health upon contact? This game is designed for the 3ds browser, so it must be coded in JavaScript ...

Incorporate information produced by a Javascript function into PHP

I have developed a website which pulls data from a file (a time value) and initiates a Javascript timer. My goal is to use PHP to continue adding the current time to the loaded time, resulting in an incremental timer that resumes from where it was last l ...

Using JavaScript to transform radio buttons into checkboxes

I have a grouping of radio buttons and a checkbox displayed on the page as shown below <html> <head> <title>Languages</title> <script type="text/javascript"> </script> </head> <body> <spa ...

What is the best way to import and export modules in Node.js when the module names and directories are given as strings?

Here is the structure of my folder: modules module-and index.js module-not index.js module-or index.js module-xor index.js moduleBundler.js The file I'm currently working on, moduleBundler.js, is re ...

Purge precise LocalStorage data in HTML/JavaScript

How can a specific item in the localStorage be cleared using javascript within an html file? localStorage.setItem("one"); localStorage.setItem("two"); //What is the method to clear only "one" ...

Why is the JS Component failing to appear on the page?

My component is not rendering on the page. Despite no errors or warnings, I have logged the gameData value and confirmed that all data is correct. Below is the function being exported: export default function AllGameDeals( gameData ){ const dealArr = ...

Dilemma arises from conflicting javascript codes

Currently, I am developing a web application where the main page features a timeline that needs to update its content automatically. To achieve this, I am utilizing the setTimeOut function of JQuery to refresh the timeline every x seconds. In addition, th ...

Looking to find the length of a word within a txt file using jQuery?

I'm facing an issue with parsing text from a file. The file in question can be accessed via the following link: File: google-books-common-words.txt [1] Word => 'THE' USED => 53097401461 [2] Word => 'OF' USED => 3096 ...

Is there a way to link the scrolling of two ag-grid data tables together for synchronized movement?

I have integrated ag-grid into my Angular project and I am looking to display two data tables (ag-grid) stacked on top of each other. Both data tables should scroll together, meaning when I scroll in table 1 or table 2, the content of both tables should m ...

Issues with the display property

After setting the display of a div tag as none in the style property, I am trying to show it based on an on-click function. However, the issue I am facing is that when I click on the function, the div displays for a brief moment then disappears again. Ca ...

Employing useEffect within Material-UI tabs to conceal the third tab

At the page's initial load, I want to hide the first two tabs. The third tab should be visible with its content displayed right away. Currently, I can only see the content after clicking on the third tab. To troubleshoot this issue, I attempted to use ...

Leveraging data generated by a CasperJS script within an AngularJS application

After using yeoman.io to create an angular.js single page application, I found myself with app.js managing routes, mycontroller.js scripts, and an index.html file filled with "bower_components" references for libraries installed through the command line us ...

How can we use JavaScript to add a class to the <html> element?

What is the method to apply a class to the root element <html> in JavaScript? ...

determining the sorting behavior of columns in Datatables

While working on my table, I referred to a Datatbles tutorial that covers sorting the third column as a percentage value. // Setting up column search - adding a text input to each footer cell $('#p_table-id tfoot th').each(function ...

Error: Access Denied - discord.js bot command cannot be executed due to lack of authorization

Every time I initiate the bot and try to execute my "ping" command, an error occurs: js:350 throw new DiscordAPIError(data, res.status, request); ^ DiscordAPIError: Missing Access at RequestHandler.execute (C: ...

Error message: "The property is not found within the specified type when using the OR operator with

Within my Angular component, I am faced with a challenge involving an Input that can be one of two types. @Input() profile: UserProfileDetails | BusinessProfileDetails; The structure of the profile template is straightforward and I want to avoid duplicati ...

Troubleshooting navigation problems in AngularJS Bootstrap Navbar

Currently, I am working on integrating AngularJS with Bootstrap3 for a mobile application. In my index.html file, I have added a navbar (navbar-fixed-top) and there are forms loaded through partials/myform.html. However, when I scroll the page and a textbo ...

Error: It seems that the window object is not defined when trying to run Firebase analytics

Encountering the error ReferenceError: window is not defined when attempting to set up Firebase analytics in my Next.js project. Below is the code snippet causing the issue: const app = initializeApp(firebaseConfig); const auth = getAuth(app); let analyti ...