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

Search form with a variety of fields that allows for searching without needing to repeat the component for each condition

I am currently facing an issue with my form that consists of multiple fields, each used to search through an API and display matching data in a table below. While I have successfully implemented this for one field, I now need it to work for all fields with ...

What causes the 'then' method of my angular service to return a resolved promise instead of the expected value?

I am perplexed as to why the "result" in this code snippet is a resolved promise instead of the actual value: searchService.getLink(vm.queryObject).then(function (result) { console.log(result); }); The implementation for the getLink() function is pro ...

Customizing the styling of buttons in Highcharts is disabled when in full screen mode

I've integrated highcharts into my Angular application and included a custom button inside the chart to navigate users to another page. However, I encountered an issue when trying to fullscreen the chart using the export menu. The position of the cus ...

How can I update a property within an object in a sequential manner, similar to taking turns in a game, using React.js?

I am currently working on a ReactJs project where I am creating a game, but I have encountered an issue. I need to alternate turns between players and generate a random number between 1 and 10 for each player, storing this random number inside their respec ...

Expanding file input fields in Javascript

I am facing an issue with my form and file input. I need to select images from a different folder. echo '<pre>'; var_dump($_FILES); echo '</pre>'; Upon submitting the form, only the last selected image is displayed, but I ...

Retrieve solely the text content from a JavaScript object

Is there a way to extract only the values associated with each key in the following object? const params = [{"title":"How to code","author":"samuel","category":"categoery","body":"this is the body"}] I'm struggling to figure out how to achieve this. ...

Using jQuery to delay hiding for 2 seconds

Hey there! I'm facing an issue with my code. The function is supposed to make #aboutPopOut slide to the left, and then after a 2-second delay, fade out the fadescreen by hiding it. The sliding part works fine, but the waiting and hiding do not seem to ...

Examining the scroll-down feature button

I'm currently experimenting with a scroll down button on my website and I'm perplexed as to why it's not functioning properly. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" c ...

Localization of date picker in material-table(Material UI)

Does anyone have experience with localizing the date picker in material-table (Material UI)? The date picker is specifically used for filtering in this scenario. import React from 'react'; import MaterialTable from 'material-table'; fu ...

AngularJS fetches the 'compiled HTML'

If I have this angularjs DOM structure <div ng-init="isRed = true" ng-class="{'red': isRed == true, 'black': isRed == false}"> ... content </div> How can I obtain the 'compiled' version of this on a cl ...

Code igniter validation with Ajax works well, especially when the error function is triggered during the validation->run process

I am currently working on creating a validation form using Ajax. Everything works perfectly when the Textbox is empty and the correct errors are displayed. However, when I fill out the form, the Ajax script stops working and goes to the error function inst ...

Aurelia's navigation feature adds "?id=5" to the URL instead of "/5"

I have set up my Aurelia Router in app.ts using the configureRouter function like this: configureRouter(config, router: Router) { config.map([ { route: ['users', 'users/:userId?'], na ...

Having difficulties with loading a Google Map using jQuery

Having some trouble loading my google map using a jquery load call. It doesn't seem to be appearing on my index page within a specific div when loaded from an external page. I've tried copying the code from the Google developers page but I can&ap ...

Is there a way to showcase the string message from BadRequest(message) utilizing Ajax?

I am currently working on implementing an API Controller. public ActionResult<Campaigns> AddCampaign([Bind("Name, Venue, AssignedTo, StartedOn, CompletedOn")] Campaigns campaigns) { try { if (ModelState.IsVal ...

What is the best way to implement JavaScript for loading and removing content based on button clicks on a webpage?

I'm in need of a vanilla JavaScript solution (I know JQuery options exist, but I want to stick to vanilla JS for now)? Currently, I am using a simple page as a testing ground for my ongoing project. The page consists of two buttons that load HTML pag ...

Oops! An error occurred while trying to load the myApp module. The module 'ui.bootstrap' is missing and causing the failure

When using Firefox, I encountered the following error: SyntaxError: syntax error xml2json.js:1 SyntaxError: syntax error ui-bootstrap-tpls-0.13.0.js:1 Error: [$injector:modulerr] Failed to instantiate module myApp due to: [$injector:modulerr] Failed to in ...

Ways to access a particular property of a child component object from the parent component

Is there a way to access a child component's "meta" property from the parent component without using the emit method? I am aware of the solution involving an emit method, but I'm curious if there is a simpler approach to achieving this. // Defau ...

Loop through two sets of data and perform multiplication on specific attributes when they match

I have a unique item that looks like this Object {SD00002:1,SD00011:3,SD00002:6} The values of the properties are set automatically. Currently, I have an array of similar objects as shown in the image below: My goal is to loop through these two objects ...

Processing made easy with jQuery

In my HTML page, I have multiple rows that represent records from a database. Each row contains input fields and a link at the end. When I click on the link, I need to capture the values of the input fields within the same row. Here is an example of the H ...

JavaScript: How to identify and select a specific item from a context menu

Currently diving into the world of JavaScript, so please keep that in mind when explaining. My main goal is to figure out a way to detect when a user triggers a right-click or uses the context menu from the keyboard. Specifically, I want to know if they s ...