Results 1 to 3 of 3

Thread: DateField and SQL

  1. #1

    Default DateField and SQL

    Hi guys,
    something strange happend when i try to edit some dates in an EditorGridPanel.
    This is my code:
    Code:
    Ext.onReady(function(){
        
        initialize();
        
        Ext.getUrlParam = function(param) {
               var params = Ext.urlDecode(location.search.substring(1));
               return param ? params[param] : params;
        }; 
    
        var idDip = Ext.getUrlParam('id');
    
            var ds_model = Ext.data.Record.create([
                'id',
                'matr_dip',
                {name: 'dal', type: 'date', dateFormat: 'Y-m-d'},
                {name: 'al', type: 'date', dateFormat: 'Y-m-d'},
                'motivazione'
            ]);
            
            var store = new Ext.data.Store({
                url: 'assenzeSearch.php',
                baseParams: {id: idDip},
                reader: new Ext.data.JsonReader({
                    id:'id'
                }, [
                'id',
                'matr_dip',
                {name: 'dal', type: 'date', dateFormat: 'Y-m-d'},
                {name: 'al', type: 'date', dateFormat: 'Y-m-d'},
                'motivazione'
                ], ds_model),
            });
            store.load();
            
            var text_edit = new Ext.form.TextField({
                allowBlank: false,
                maxLength: 45
            });
            
            var date_edit = new Ext.form.DateField({
                 format: 'Y-m-d'
                
            });
    
            var grid = new Ext.grid.EditorGridPanel({
                                                    
                renderTo: 'asse',
                frame:true,
                //title: 'Assoggettamenti Istituti Previdenziali',
                height:330,
                width:640,
                loadMask: true,
                store: store,
                clicksToEdit: 2,
                columns: [
                    {header: "Dal", dataIndex: 'dal', renderer: function(date) { return date.format("d.m.Y"); }, editor: date_edit},
                    {header: "Al", dataIndex: 'al', renderer: function(date) { return date.format("d.m.Y"); }, editor: date_edit},
                    {header: "Motivazione", dataIndex: 'motivazione', editor: text_edit}
                    
                ],
                sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true
                }),
                listeners: {
                    afteredit: function(e){
                        var JSONObject = new Object;
                        JSONObject.id = e.record.id;
                        JSONObject.field = e.field;
                        JSONObject.value = e.value; 
                        JSONstring = JSON.stringify(JSONObject);
                        Ext.Ajax.request({
                                        url: 'assenze-update.php?id='+idDip+'&json='+JSONstring,
                                        method: 'get',
                                        success: function(response, options) {
                                                e.record.commit();
                                        },
                                        failure: function(response, options) {
                                                e.record.reject();
                                                Ext.MessageBox.alert ('Messaggio',response.responseText);                                      
                                        }
                        });
                    }
                }
            });
        });
    If i select a date using the calendar it show me the right date but when i send the json i've some problem.
    Maybe an example could explain things better!

    I try to insert the date 2010-04-30 (yyyy-mm-dd) but Firebug says that:

    json{"id":"1","field":"dal","value":"2010-04-29T22:00:00.000Z"}

    Where is my mistake?I really can't find it!
    How can i send only the date
    2010-04-30 whitout other info??
    Thank you guys!!!

  2. #2
    Ext JS Premium Member cnelissen's Avatar
    Join Date
    Sep 2007
    Location
    California
    Posts
    226

    Default

    If your type is 'date' in your store definition, this will always have the time specified with the date, since that is the format of a timestamp in javascript. You can always just parse out that data on your backend script before you write to a database, I have found that is the easiest solution.

    Also, why dont you just use a data writer on your store instead of your crazy afterEdit function. I.e.

    Code:
    Ext.onReady(function(){
    	initialize();
    	
    	Ext.getUrlParam = function(param) {
    		var params = Ext.urlDecode(location.search.substring(1));
    		return param ? params[param] : params;
    	}; 
    	
    	var idDip = Ext.getUrlParam('id');
    	
    	var store = new Ext.data.Store({
    		url: 'assenze-actions.php', // You will need to combine assenzeSearch.php & assenze-update.php into one file
    		baseParams: {id: idDip},
    		reader: new Ext.data.JsonReader({
    			id: 'id'
    		}, [
    			{name: 'id'},
    			{name: 'matr_dip'},
    			{name: 'dal', type: 'date', dateFormat: 'Y-m-d'},
    			{name: 'al', type: 'date', dateFormat: 'Y-m-d'},
    			{name: 'motivazione'}
    		]),
    		writer: new Ext.data.JsonWriter({
    			encode: true,
    			encodeDelete: true
    		})
    	});
    	store.load({
    		params: {'xaction': 'search'} // This will do a search action on load
    	});
    	
    	var text_edit = new Ext.form.TextField({
    		allowBlank: false,
    		maxLength: 45
    	});
    	
    	var date_edit = new Ext.form.DateField({
    		 format: 'Y-m-d'
    	});
    
    	var grid = new Ext.grid.EditorGridPanel({
    		renderTo: 'asse',
    		frame:true,
    		//title: 'Assoggettamenti Istituti Previdenziali',
    		height:330,
    		width:640,
    		loadMask: true,
    		store: store,
    		clicksToEdit: 2,
    		columns: [
    			{header: "Dal", dataIndex: 'dal', renderer: function(date) { return date.format("d.m.Y"); }, editor: date_edit},
    			{header: "Al", dataIndex: 'al', renderer: function(date) { return date.format("d.m.Y"); }, editor: date_edit},
    			{header: "Motivazione", dataIndex: 'motivazione', editor: text_edit}
    			
    		],
    		sm: new Ext.grid.RowSelectionModel({
    			singleSelect: true
    		})
    	});
    });
    - Clint Nelissen

  3. #3

    Default

    Thank you Clint!Yes I've solved it by parsing after writing...Thanks for the advice, i'll try to follow it!!!

Posting Permissions

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