Results 1 to 4 of 4

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Nov 2012
    Vote Rating

    Default 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:
    var l_alsChampsMois, l_stoDonneesMois;
        try {
            l_alsChampsMois = [
              {name: "date_mois", type: "date", dateFormat: "Y-m-d"},
              {name: "indice", type: "integer"}
            l_stoDonneesMois = new{
                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: {
                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!...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
    Vote Rating


    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
    Vote Rating

    Default 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
    Vote Rating

    Default 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',

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts