Hybrid View

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    101
    Vote Rating
    1
    Jean-David Lanz is on a distinguished road

      0  

    Default Unanswered: How can I access a date typed field from an ExtJS JSonStore?

    Unanswered: How can I access a date typed field from an ExtJS JSonStore?


    Hello all,

    I've been trying to retrieve a date value and an integer value from the database, using the following code:
    Code:
    var l_alsChampsMois, l_stoDonneesMois;
    
        try {
            l_alsChampsMois = [
              {name: "date_mois", type: "date", dateFormat: "Y-m-d"},
              {name: "indice", type: "integer"}
            ];
    
            l_stoDonneesMois = new Ext.data.JsonStore({
                fields: l_alsChampsMois,
                autoLoad: false,
                proxy: {
                    type: "ajax",
                    url: "/commun/req_sql/req_ind_per_mois.php",
                    reader: {
                        type: "json",
                        root: "rows"
                    },
                    // some configs to use jsFiddle echo service (you will remove them)
                    actionMethods: {
                        read: "POST"
                    },
                   extraParams: {
                        key:"test"
                    }
                },
                listeners: {
                    load: function(objStore, alsLignes, blnOk, objOptions) {
    window.alert("Mois fin : " + objStore.getAt(0).get("date_mois"));
                    }
                }
            });
    
        l_stoDonneesMois.load({params:            {
                                    p_idsoc:    l_strIdSociete,
                                    p_mois:        l_datDebut.getMonth() + 1,   
                                    // getMonth renvoie 0 pour janvier, etc. 
                                    p_annee:    l_datDebut.getFullYear(),
                                    p_debut:    1,
                                    p_etape:    1
                                    } 
                                });
    with l_strIdSociete and l_datDebut being variables previously assigned and /commun/req_sql/req_ind_per_mois.php the PHP page that retrieves the data and converts it to JSON.

    It seems to work fine (indeed, Firebug tells me the load does retrieve a data structure with "date_mois" and "indice" containing the values I expect them to), only the window.alert returns undefined. If I replace "date_mois" with "indice", it returns the expected value for "indice".

    I've tried to use objStore.getAt(0).getData()["date_mois"], to no avail.

    My only clue about this is that "date_mois" in the data structure shown by Firebug is an Object, but even so it shouldn't be undefined, now should it? I looked up http://docs.sencha.com/ext-js/4-1/#!...Field-cfg-type that wasn't exactly forthcoming with straight answers.

    So what did I do wrong there?

  2. #2
    Sencha User
    Join Date
    Sep 2011
    Posts
    568
    Answers
    58
    Vote Rating
    68
    ettavolt is just really nice ettavolt is just really nice ettavolt is just really nice ettavolt is just really nice

      0  

    Default


    If it is an Object, then toString representation would be [object Object], which can be parsed in correct date with any format. Server should convert dates to proper strings.

  3. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Answers
    1
    Vote Rating
    0
    ascii is on a distinguished road

      0  

    Default Please post your JSON

    Please post your JSON


    Perhaps the JSON is not correctly formatted. You could post it here for us to see. Is there a "rows" object that contains the other fields? I ask because the other variable names are in French and "rows" is not - perhaps it was copied from an example.

  4. #4
    Sencha User 123lal's Avatar
    Join Date
    Feb 2012
    Posts
    32
    Vote Rating
    0
    123lal is on a distinguished road

      0  

    Default You need to recreate the date format

    You need to recreate the date format


    by default the mysql gives date format in format

    after retrieving date from mysql you need to change the date format to

    the corresponding format that you were used in the date field

    if you are not customised the

    xtype : 'datefield',
    the

    nb the format will be 12/04/2012 that is month/date/year


    so i think you need to change the retrieved data from the database server to the above format in the json

    then it will load to the xtype : 'datefield',


    if you found problem again please post your json and xtype used for date field