Issue with ExtJS causing store to not load properly

I have been working on this issue for over a week now and cannot seem to get it resolved. The webservice is returning data, which I can see, but the store is not loading it correctly. The only time I managed to display the entire response in the grid was when I created an ArrayStore and used loadRawData, although the formatting was off. Can someone please assist me in identifying why my store is not loading the data properly into the grid:

   Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
         { name: 'connTime', type: 'string' },
         { name: 'userName', type: 'string' },
         { name: 'clientName', type: 'string' },
         { name: 'feedUrl', type: 'string' },
         { name: 'dconnTime', type: 'string' },
         { name: 'errMessage', type: 'string' },
         { name: 'ip', type: 'string' }
  ]
});

var myStore = Ext.create('Ext.data.Store', {
    model: 'User'
 });


 Ext.Ajax.request({
    url: 'http://dfsdfsfsfs/WCFService/WebService1.asmx/getValue',
    method: 'GET',
    success: function (response, options) {
        var s = response.responseText;
        Ext.MessageBox.alert(s, 'WOO WOO');
        myStore.loadData(s);
    },
    failure: function (response, options) {
        Ext.MessageBox.alert('FAILED MF', 'Unable to GET');
    }
});



  var grid = Ext.create('Ext.grid.Panel', {
    store: myStore,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text: 'Query',
            width: 25,
            sortable: false,
            dataIndex: 'userName'
        },
        {
            text: 'Count',
            width: 5,
            sortable: true,
            renderer: change,
            dataIndex: 'ip'
        },
        {
            text: 'Last Updated',
            width: 76,
            sortable: true,
            dataIndex: 'connTime'
        },
        {
            text: 'Disconnect Time',
            width: 10,
            sortable: true,
            renderer: change,
            dataIndex: 'dconnTime'
        },
        {
            text: 'Client',
            width: 10,
            sortable: true,
            renderer: change,
            dataIndex: 'clientName'
        }

    ],
    height: 350,
    width: 800,
    title: 'Active Queries',
    renderTo: 'grid-example',
    viewConfig: {
        stripeRows: true
    }
});

.....

I attempted a different approach with the following code, but did not even receive the ajax response:

 var newStore = Ext.create('Ext.data.ArrayStore', {
    model: 'User',
    proxy: {
        type: 'ajax',
        url: 'http://dfsdfsfsfs/WCFService/WebService1.asmx/getValue',
        reader: {
            type: 'json',
            root: 'd',
            successProperty: 'success'
        },
        success: function (response, options) {
            var s = response.responseText;
            Ext.MessageBox.alert(s, 'LA LA LA');
            newStore.loadData(s);
        },
        failure: function (response, options) {
            Ext.MessageBox.alert('FAILED AGAIN', 'SUCKS');
        }
    }
});

EDIT:

Server Response:

{"d":{"connTime":null,"userName":"101591196589145","clientName":null,
   "feedUrl":null,"dconnTime":null,"errMessage":null,"ip":null}}

The "d" root element was manually added by me and is not part of the original web response. I appended it myself:

{"connTime":null,"userName":"101591196589145","clientName":null,"feedUrl":null,
"dconnTime":null,"errMessage":null,"ip":null}}

EDIT 2:

  Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
         { name: 'value', type: 'string' },
         { name: 'tag', type: 'string' }
    ]
});


var newStore = new Ext.data.JsonStore({
    model: 'User',
    proxy: {
        type: 'ajax',
        url: 'http://localhost:52856/WCFService/WebService1.asmx/getRules',
        reader: {
            type: 'json',
            root: 'rules',
            idProperty: 'value'                
        },
        success: function (response, options) {
            var s = response.responseText;
            Ext.MessageBox.alert(s, 'LA LA LA');
            newStore.loadData(s);
        },
        failure: function (response, options) {
            Ext.MessageBox.alert('FAILED AGAIN', 'SUCKS');
        }
    }
 });

  var grid = Ext.create('Ext.grid.Panel', {
    store: newStore,
    stateful: true,
    columns: [

Here is the new json format I am attempting:

{"rules":[{"value":"101591196589145","tag":"16"},
 {"value":"102890809752267","tag":"16"},    
 {"value":"107821192690513","tag":"16"},    {"value":"111517428886211","tag":"16"},
{"value":"117389718398171","tag":"16"},{"value":"12099149051","tag":"16"},

I believe the issue lies with the ext.ajax.request call. The request is made before the store is defined, resulting in the data not being loaded. How can I overcome this?

Answer №1

Let me provide you with an example for reference in comparison with your code.

// model definition
Ext.define('SampleModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'YOUR_ID', type: 'int'},
        {name: 'YOUR_NAME', type: 'string'}
    ]
});

// store definition
var storeDefinition = new Ext.data.JsonStore({
    model: 'SampleModel',
    proxy: {
        type: 'ajax',
        url: '/your/url/path/data.php',
        reader: {
            // root and idProperty are crucial
            type: 'json',
            root: 'rootList',
            idProperty: 'YOUR_ID'
        }
    }
});

The key components here are root and idProperty. The root signifies the root node of the json object, while the idProperty represents the unique id within the json object.

To handle success and failure responses, ensure to include success or failure data inside the json object. It is not mandatory to explicitly specify a success property in the reader section. For instance;

public function dnr_info()
{
    $dnr    = $this->input->get('dnr', TRUE);
    $subsys = $this->input->get('subsys', TRUE);
    $data['success'] = TRUE;
    $data['data'] = $this->dnr->get_dnr_info($dnr, $subsys);
    echo json_encode($data);
}

The above function will return the success property within the json object.

Moreover, below is the sample JSON response from the server:

{"success":true,"data":{"SUBSYS_ART_NR":"136451","ART_NR":"459993","ACTION_DESC":"BAKKAL AKTİVİTESİ (176)","ACTIONS_NR":"130012676","START_DATE":"19.12.2013","STOP_DATE":"16.01.2014","DISCOUNT_TYPE":"SPECIAL PRICE","LEVEL_TYPE":"QUANTITY","LEVEL_IMPACT":"MULTIPLE","BASIS":"ARTICLE","LEVEL_1":"1 ADET","VALUE_1":"5,92","NWW_VK_PREIS":"6.69","KOLLI_VK_PREIS":"6.69"}}
// another example specifying root as articleList and idProperty as ARTICLE_ID 
{"articleList":[{"ARTICLE_ID":"193","ART_NR":"225","ART_DESC":"27*1\/5LT.M.NEK.TAMEK.","SORTEN_TEXT":"ELMA","VAR":"1","GEBI":"1","SUBSYS_ART_NR":"225","NWW_VK_PREIS":"14.49","KOLLI_VK_PREIS":"14.49","DNR_ID":null,"STATUS":"0"}]}

Answer №2

It's unclear how you ended up in this situation. There are numerous examples of loading a grid available for download in the SDK. The Proxy does not have a failure/success method.

You can check out the Fiddle here. Here is the functional code:

Ext.onReady(function() {

    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: [{
            name: 'value',
            type: 'string'
        }, {
            name: 'tag',
            type: 'string'
        }]
    });


    var store = new Ext.data.Store({
        model: 'User',
        proxy: {
            type: 'ajax',
            url: 'data.json',
            reader: {
                type: 'json',
                root: 'rules'
            }
        }
    });
    store.load();

    var grid = new Ext.grid.Panel({
        renderTo: Ext.getBody(),
        width: 400,
        height: 400,
        store: store,
        columns: [{
            text: 'Value',
            dataIndex: 'value',
            flex: 1
        }, {
            text: 'Tag',
            dataIndex: 'tag'
        }]
    });
});

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

Tips on setting an expiration time for verification codes in a Node.js environment

What is the best way to implement an expiration time for this verification code? I need it to be deleted from the database after 10 minutes. var fourcode = Math.floor(1000 + Math.random() * 9000); app.post("/sendforgetpassword", async (req, re ...

Utilizing npm/buffer package within a TypeScript module

I'm interested in implementing this NPM package: https://www.npmjs.com/package/buffer I'm unsure about how to convert this line of code into typescript: var Buffer = require('buffer/').Buffer Could you provide me with the correct code ...

What is the best way to pass the "getjson" capability from one function to another in a seamless manner?

Currently, I am dealing with a situation where a getjson call is used to retrieve a large amount of data. However, I find myself constantly having to check if the data is null or not. Here is an example: if (data.Height == "") { $(&ap ...

What is the most efficient way to transform HTML into React components effortlessly?

I have been attempting to automate the process of converting HTML into React components. I followed the link below to automatically convert HTML into React components: https://www.npmjs.com/package/html-to-react-components However, I encountered an issue ...

Establish the starting time for the timer and use the setInterval() function according to the seconds stored within the object

How can I configure the values of timerOn, timerTime, and timerStart to make the watch start counting from 120 seconds? Currently, the clock starts counting from 3 minutes and 22 seconds, but it should start from 2 minutes. You can find all the code here: ...

A comprehensive guide on displaying data in Angular using an API

I have encountered an issue while trying to display data from an API in the 'home.component.html'. Although my 'home.component.ts' successfully fetches the data from the service, I'm facing difficulty rendering it in 'home.com ...

Tips for refreshing the page upon Geolocation request

I am working on a HTML5 project that requests geolocation from the user. Here is an image of what it looks like: My main query is: Is there a way to refresh the page automatically once the user grants permission to share their location? Are there any Jav ...

Filtering and displaying results with Django and Ajax: A step-by-step guide

I have been working on filtering and displaying data in Django based on user selections from a drop-down box. I am utilizing an Ajax call to send a request to Django views, where the filtering of data takes place. For example, when a user selects "Airline ...

A guide to incorporating Material-UI ThemeProvider and WithStyles with Typescript

I've been feeling frustrated lately as I've been dedicating the past few days to migrating my React application from JavaScript to TSX. While I appreciate the type checking that TSX provides, I'm struggling with understanding how to implemen ...

Using AngularJS to inject a variable into the standard filter

Currently, I am attempting to develop a custom filter that mimics the functionality of the standard Angular filter in HTML, with the distinction that it accepts a variable as input rather than a fixed value. For instance, within my html document, you may ...

Tips for utilizing a printer to print HTML content in PHP

I've stored HTML content in a variable as shown below: $message ="<div> <table align='center'> <tr><td><h1>Tipo de Documentos Report</h1></td></tr> <tr><td>< ...

What is the best way to send a Rails AJAX form upon clicking?

I'm looking to implement AJAX form submission in Rails using a button. Here's my current code: Controller: def list @events = ExternalEvent.all if !params[:city_id].nil? @events = @events.where(city_id: params[:city_id]) end respond ...

show up on page where I am located, not just in the center

My AJAX code displays 81 products per page. When I click the add to cart button, a div appears in the center of the page. However, when I add a product to the last or bottom of the page, the div always appears in the center and I have to scroll up to see ...

Tips for automatically closing a dropdown menu when it loses focus

I'm having some trouble with my Tailwind CSS and jQuery setup. After trying a few different things, I can't seem to get it working quite right. In the code below, you'll see that I have placed a focusout event on the outer div containing th ...

Tips for concurrently and asynchronously executing multiple AJAX requests

I am working with a javascript object named Agendamento which includes the following key parts: const Agendamento = { // ... storeResultados: async function (consulta) { //... $.ajax({ type: 'POST', ...

Implementing Axios interceptor is a common practice in Vue.js applications to central

Hello everyone, I'm facing a problem with the interceptor in VueJS. I can't seem to figure out where the issue lies and it's driving me crazy... I've gone through various tutorials and read numerous posts on stackoverflow, but everythi ...

Mastering the Art of Defining JavaScript Classes in React-Native

In my React Native project, I am faced with a situation where I need to create a new class: class customClass { email: string; name: string; constructor() { setUser(fbid: string, token: string): boolean { To keep things organized, I decide ...

Obtain the inner HTML of a component and store it as a variable in Vue.js 2

Imagine I have a vuejs component named child-component that is inserted into a parent component in the following manner. <child-component> <div>Hello</div> </child-component> Please note, this does not represent the template of ...

"Enhance Your Website with jQuery Mobile's Multi-Page Setup and Panel

I am currently facing the challenge of managing multiple pages within a single document and I would like to utilize jQM 1.3's Panel widget to control navigation between these pages. However, the issue arises from the requirement that Panels must be co ...

What is causing the javascript in my svg files not to function when embedded in an html document?

I have the following code for an SVG: <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="470px" height="260px" version="1.1" onload="addEvent ...