1. #1
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default Answered: Binding a Grid to Form. datefield

    Answered: Binding a Grid to Form. datefield


    I have a problem with binding date in grid to date in field. Date is not displayed in datefield.
    What could be the problem?

    datefield code:
    PHP Code:
    ...
    {
    xtype'datefield'
    name'criticaldate'
    emptyText'Critical date'
    editablefalse
    format'Y-m-d'
    submitFormat'Y-m-d'}
    ... 
    model:
    PHP Code:
    ...
    {
    dateFormat'Y-m-d'
    name'criticaldate'}
    ... 
    grid:
    PHP Code:
    ...
    {
    xtype'gridcolumn',
    renderer: function(value) {return Ext.util.Format.date(value'Y-m-d');},
    dataIndex'criticaldate',
    text'Critical date'}
    ... 

  2. jnesis, thank you!
    The date format in grid and field can be any. But in model must be date.


    Two solutions to the problem is change model and convert string to date.

    change model:
    Code:
    {
                name: 'criticaldate',
                type: 'date'
            }
    convert string to date and set datefield value:
    Code:
    var d = new Date(selected[0].get('criticaldate'));
    form.query('datefield[name="criticaldate"]')[0].setValue(d);

  3. #2
    Sencha Premium Member aaugen's Avatar
    Join Date
    Oct 2010
    Location
    Mulhouse, France (68200)
    Posts
    48
    Answers
    12
    Vote Rating
    18
    aaugen will become famous soon enough aaugen will become famous soon enough

      0  

    Default


    Hi,

    Maybe you forgot to set "value" property in datefield.
    ie: value: new Date() or value: record.criticaldate.

    I also suggest you to use datecolumn rather than gridcolumn with renderer method.
    Hoping this helps you.



    Alexandre AUGEN - Computer Engineer
    JNESIS
    20c rue du Chemnitz
    68200 Mulhouse - France
    Tél: +33 3 89 36 60 39

  4. #3
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default


    PHP Code:
    onGridpanelSelectionChange: function(selected) {
    var 
    selected[0];
    if (
    s) {
      var 
    form Ext.getCmp('reqaddform');
      
    form.loadRecord(s);
    }

    text fields are filled in, and the date field is no.

  5. #4
    Sencha Premium Member aaugen's Avatar
    Join Date
    Oct 2010
    Location
    Mulhouse, France (68200)
    Posts
    48
    Answers
    12
    Vote Rating
    18
    aaugen will become famous soon enough aaugen will become famous soon enough

      0  

    Default


    Ok,

    Try to specify type of criticaldate field in your model like this:
    Code:
    .., { name: 'criticaldate', type: 'date', dateFormat: 'Y-m-d' }, ...
    I suppose that criticaldate attribute in your model is text rather than date...
    Hoping this helps you.



    Alexandre AUGEN - Computer Engineer
    JNESIS
    20c rue du Chemnitz
    68200 Mulhouse - France
    Tél: +33 3 89 36 60 39

  6. #5
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default


    grid.column.Date:
    Code:
    {
    xtype: 'datecolumn',
    dataIndex: 'criticaldate',
    text: 'Criticaldate',
    format: 'Y-m-d'
    }
    model:
    Code:
    {
    dateFormat: 'Y-m-d',
    name: 'criticaldate',
    type: 'date'
    }
    In the table date is no longer displayed. On the form the date is still not displayed. If I do not specify a date format(format: 'Y-m-d'), then the date is also not displayed.

    data from backend:
    Code:
    $sqlstr = "select * from requests";
    
    
                $STH = $DBH->query($sqlstr);
                $STH->setFetchMode(PDO::FETCH_ASSOC);
                $json = array();
                while($row = $STH->fetch()) {
                    $json[] = $row;
                }
                echo json_encode(array('success' => true, 'data' => $json));
    in mysql database criticaldate is datetime

  7. #6
    Sencha Premium Member aaugen's Avatar
    Join Date
    Oct 2010
    Location
    Mulhouse, France (68200)
    Posts
    48
    Answers
    12
    Vote Rating
    18
    aaugen will become famous soon enough aaugen will become famous soon enough

      0  

    Default


    In your javascript console, execute specific instruction to get your store et check in if criticaldate is filled (data/items).
    Code:
    Ext.getStore('yourstore');
    Because you specify dateFormat: 'Y-m-d', verify that your data feed is in good format, ie: 2013-09-01 (with 0 for month and day).
    Hoping this helps you.



    Alexandre AUGEN - Computer Engineer
    JNESIS
    20c rue du Chemnitz
    68200 Mulhouse - France
    Tél: +33 3 89 36 60 39

  8. #7
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default


    data is returned in this format:
    Code:
    "criticaldate":"2013-09-18 00:00:00"

  9. #8
    Sencha Premium Member aaugen's Avatar
    Join Date
    Oct 2010
    Location
    Mulhouse, France (68200)
    Posts
    48
    Answers
    12
    Vote Rating
    18
    aaugen will become famous soon enough aaugen will become famous soon enough

      0  

    Default


    Ok,
    so you need to specify in model a date format in association with your data feed to create date objet like this:
    Code:
    ...
    dateFormat: 'Y-m-d  H:i:s',
    ...
    Hoping this helps you.



    Alexandre AUGEN - Computer Engineer
    JNESIS
    20c rue du Chemnitz
    68200 Mulhouse - France
    Tél: +33 3 89 36 60 39

  10. #9
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default


    I modified the model:
    Code:
    {
                name: 'criticaldate'
            }

    Now the date is displayed in the table
    :
    Code:
    {
                                        xtype: 'datecolumn',
                                        dataIndex: 'criticaldate',
                                        text: 'Critical date',
                                        format: 'Y-m-d'
                                    }
    But in the fieldcontainer still not displayed. Code fieldcontainer:
    Code:
    {
                        xtype: 'datefield',
                        name: 'criticaldate',
                        emptyText: 'Critical date',
                        editable: false,
                        submitFormat: 'Y-m-d H:i:s', //'Y-m-d'
                        format: 'Y-m-d H:i:s' //'Y-m-d'
                    },
    Nor Y-m-d, nor Y-m-d H:i: s.

    With the model "dateFormat: 'Y-m-d H:i: s'", the same.
    Can be important information - date submit work fine.

  11. #10
    Sencha User
    Join Date
    Aug 2013
    Posts
    7
    Answers
    1
    Vote Rating
    0
    odinkubometr10 is on a distinguished road

      0  

    Default


    jnesis, thank you!
    The date format in grid and field can be any. But in model must be date.


    Two solutions to the problem is change model and convert string to date.

    change model:
    Code:
    {
                name: 'criticaldate',
                type: 'date'
            }
    convert string to date and set datefield value:
    Code:
    var d = new Date(selected[0].get('criticaldate'));
    form.query('datefield[name="criticaldate"]')[0].setValue(d);

Thread Participants: 1

Tags for this Thread