Understanding the Scope of Variables in Dojo JavaScript

I have integrated dgrid into my project and I am facing an issue with setting the dataStore externally. Initially, when the page loads, I trigger aliasTicket.load() to initialize the grid. However, at this point, the datasource is null. It only gets populated with data once a query is made using setAliasSource(aliasData);.

Although there are no apparent errors, the grid remains empty even after updating the aliasStore with data. The changes in data are not reflected on the grid even after a refresh. How can I ensure that the updated data is displayed on the grid post-query?

Javascript Object


var aliasTicket = (function (){

var aliasData = [];

require(["dojo/store/Observable", "dojo/store/Memory"]);   
var aliasStore = new dojo.store.Observable(new dojo.store.Memory({
    data: aliasData,
    idProperty: "id"
}));  

return{         

    load:function(){

        require([
                 ........

               ], function(declare, Memory, OnDemandGrid, ColumnSet, Selection,
                 selector, Keyboard, DijitRegistry, editor, ColumnHider,
                 registry, Observable, lang) {

            aliasData = this.aliasData;

            var Store = this.aliasStore = new dojo.store.Observable(new dojo.store.Memory({
                data: aliasData,
                idProperty: "id"
            }));

            console.log(Store);

            var CustomAliasNameGrid = declare([OnDemandGrid, selector, Selection, Keyboard, editor, DijitRegistry, ColumnHider]);

            var aliasNameGrid = new CustomAliasNameGrid({
                store: Store,
                columns: {
                    id: {
                        label: "Id",
                        field: "id",
                        hidden: true,
                        autoSizeColumn: true
                    },

                    employeeTicketId: {
                        label: "Employee Ticket Id",
                        field: "employeeTicketId",
                        hidden: true,
                        autoSizeColumn: true
                    },

                    chkBox: selector({}),

                    aliasName: {
                        label: "Alias Names",
                        field: "aliasTicketName",
                        autoSizeColumn: true,
                        formatter: function(str) {
                            return str.replace(/\w\S*/g, function(txt) {
                                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
                            });
                        }
                    }

                },
                selectionMode: "none",
                loadingMessage: "Loading data...",
                noDataMessage: "No results found....",
                allowSelectAll: true
            }, "aliasNameGrid");  

            aliasNameGrid.refresh()

        }); 

    },

    setAliasSource: function (data){
        console.log(data);
        this.aliasSource = data;            

    },

    setAliasData: function (data){
        this.aliasData = data;              
    },

    getAliasSource: function (){
        return this.aliasSource;
    }       

};  

})();

Setting Data Store Data


aliasData = [{.....},
             {.....},
             {......];          

require(["dijit/dijit"]);
aliasTicket.setAliasSource(aliasData);              
dijit.byId('aliasNameGrid').refresh();

Answer №1

In your code, you are assigning 'this.Store' to an object array instead of a true 'dojo store' object. It looks like there is a local variable named 'Store' inside the grid code, but it's not clear if that is being used as intended.

It seems like you may need to set the store for the grid and then refresh it in order for it to work properly. Here is a revised version of your code:

setAliasSource: function (data){
    console.log(data);
    this.Store = data;
    dijit.byId('aliasNameGrid').set("store", new dojo.store.Observable(new dojo.store.Memory({ data: data, idProperty: "id" }));
    dijit.byId('aliasNameGrid').refresh();
},

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

What methods can I use to identify when a browser autofills a saved password during a web login process?

My website has a feature that activates the login button when a user enters their username and password. However, an issue arises when the browser autofills this information, as the login button does not get enabled in such cases. Is there a way to use J ...

Converting a numpy array into a bytestring using Python serialization

I'm having trouble converting a numpy array into a JSON string where the value should be in byte format. The API I am using requires the data to be in string form, and then it decodes the data with np.fromstring(post_data.get("mask_image")). post_dat ...

Leveraging node.js for website development

After setting up Node.js and installing the latest version of Express 3.4.1, I started coding. However, when trying to send parameters other than /, I encountered an error. In my index.js file, I have the following code: exports.speakers = function(req, ...

Attach a unique anti-forgery identifier to XMLHttpRequest

Essentially, I am having an issue with validating the token in my JavaScript code. Everything works fine without validation, but once I try to validate the token, I receive an error stating The required anti-forgery form field "__RequestVerificationToken" ...

I'm experiencing trouble with Shopify as it appears to be failing to execute

I have been attempting to incorporate a tracking pixel into my project. Thus far, I have tested the code in various environments, both with and without wrapping it in a function and deploying it using window.onload. If you would like to see the implementa ...

Remove external elements from the JSON and only focus on the internal ones

I am dealing with a JSON that starts with an object containing all the rest of the data: { "mainObject": { "other stuff here 1" : "aaa", "other stuff here 2" : "bbb", ... "other stuff here 2000" : "zassbbb" } } After getting the entir ...

What is the best way to establish communication between a server and client using sockets in Node.js?

Presently, I am in the process of developing a JavaScript application using AppJS. I'm encountering some difficulties understanding the communication between the client and server. Issue with Menu Bar and Socket Interaction The main challenge lies ...

Incorrect .offset().top calculation detected

Within a webpage, I have multiple sections. Positioned between the first and second section is a navbar menu. As the user scrolls down and the navbar reaches the top of the page, a function is triggered to fix it in place at the top. While this functionali ...

What benefits does incorporating a Web API bring to an ASP.NET MVC (5) venture?

For my ASP.NET MVC 5 enterprise web application, I have been frequently using AJAX to communicate with the server app through controller actions returning JSON results. The parameter binding in the action methods has been working smoothly when passing JSON ...

What is the method to identify the key responsible for triggering a textbox input event?

Suppose there is a textbox on the webpage: <input id='Sub' type='text'> To capture each time the input changes, you can use the following code: sub = document.getElementById('Sub'); sub.addEventListener('input&a ...

Error encountered: `npm ERR! code E503`

While attempting to execute npm install on my project, which was cloned from my GitHub repository, I encountered the following error: npm ERR! code E503 npm ERR! 503 Maximum threads for service reached: fs-extra@https://registry.npmjs.org/fs-extra/-/fs-ex ...

The placeholder image is failing to load correctly alongside the cards in ReactJs

Currently, I am working on a project that involves loading a list of cards with data fetched from an external API. The data includes fields like "Id, title, URL, and thumbnail URL." As it stands, the cards display an image only if a thumbnail URL is provi ...

I am attempting to display text in the input box on the console, but unfortunately, I am not seeing any changes in the console when typing

I have this code, but I am not getting any output when I run it: import { restaurantList } from "../config"; import { RestrauntCard } from "./Restraunt"; const Body = () => { const searchText = "KFC"; return ( <& ...

Fetching JSON data from an external URL using AngularJS

Check out this URL that shows JSON data in the browser: I attempted to store the data in a variable with the following code: $http.get('http://api.geosvc.com/rest/US/84606/nearby?apikey=4ff687893a7b468cb520b3c4e967c4da&d=20&pt=PostalCode& ...

What is the best way to conceal an element and its descendants from being read by screen readers?

What is the best method to conceal an element and its children from both screen readers and keyboard access? Currently, I am focused on improving accessibility for the pages under my maintenance. However, there are certain advertising banners that cannot ...

What is the most effective method for populating data within a browser window?

I have a list of files stored in $scope.data that I retrieved from the searchFactory. Now, my goal is to display these files in the browser window. How can I accomplish this task? ctrl.js $scope.displayFiles = function (){ $window.open($scope.dat ...

Utilizing JSON Data in HTML: A Step-by-Step Guide

I am currently working with a JSON file along with a JavaScript file named list.js. My goal is to extract the data from this JSON file in an HTML document called index.html. Can someone guide me on how to establish the connection between them? Below is th ...

Surprising outcome discovered while using JSON auto

I have the following three tables with sample data: Employee, Address, States /****** Object: Table [AzureSearch].[Address] Script Date: 11/2/2021 2:16:55 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [AzureSearch].[Address] ...

Refresh the page on the same tab after making an AJAX request

HTML: <table border="1"> <tr id="main_account"> <td width="50%"> <h3 style="margin-left:10px">Details</h3> <table width="270"> <tr> <td& ...

Transforming a JSON object into an "array" format

I have encountered a formatting issue when trying to structure data for plot.ly as follows: var data = [ { x: [cow, horse, chicken] y: [20, 14, 23], type: 'bar' } My current approach to retrieve data from mySQL is shown below: ...