ee3a84w
Thursday, January 8, 2009

value not being passed to php

  • i have a grouping editable grid, all values on update are passing to php file but in case of one - date - value is not showing up in firebug, only other data like field and stuff.. can anyone point out the reason for that?

    Here's the code:

    Ext.onReady(function(){

    Ext.QuickTips.init();

    var xg = Ext.grid;

    var Task = Ext.data.Record.create([
    {name: 'done', type: 'int'},
    {name: 'project', type: 'string'},
    {name: 'id', type: 'int'},
    {name: 'task', type: 'string'},
    {name: 'hours', type: 'float'},
    {name: 'rate', type: 'float'},
    {name: 'cost', type: 'float'},
    {name: 'date', type: 'date', dateFormat:'d/m/Y'}
    ]);

    var reader = new Ext.data.JsonReader({
    root: 'results',
    totalProperty: 'count',
    id: 'id'},
    Task);

    var ds = new Ext.data.GroupingStore({
    proxy: new Ext.data.HttpProxy({url: 'data.php?task=showData'}),
    reader: reader,
    sortInfo: {field: 'date', direction: "ASC"},
    groupField:'project'
    });

    ds.load();

    // define a custom summary function
    Ext.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
    return v + (record.data.hours * record.data.rate);
    }

    var summary = new Ext.grid.GroupSummary();

    var grid = new xg.EditorGridPanel({
    ds: ds,
    columns: [
    {
    id: 'id',
    header: "id",
    width: 20,
    sortable: true,
    dataIndex: 'id',
    hideable: true,
    hidden: true
    },
    //checkColumn,
    {
    header: "Projekts",
    width: 20,
    sortable: true,
    dataIndex: 'project',
    editor: new Ext.form.ComboBox({
    typeAhead: true,
    triggerAction: 'all',
    transform:'projekti',
    lazyRender:true,
    forceSelection: false,
    listClass: 'x-combo-list-small'
    })
    },{
    id: 'task',
    header: "Uzdevums",
    width: 80,
    sortable: true,
    dataIndex: 'task',
    summaryType: 'count',
    hideable: false,
    summaryRenderer: function(v, params, data){
    return ((v === 0 v > 1) ? '(' + v +' Uzdevumi)' : '(1 Uzdevums)');
    },
    editor: new Ext.form.TextField({
    allowBlank: false
    })
    },{
    header: "Datums",
    width: 25,
    sortable: true,
    dataIndex: 'date',
    summaryType:'max',
    renderer: Ext.util.Format.dateRenderer('d/m/Y'),
    editor: new Ext.form.DateField({
    format: 'd/m/Y',
    minValue: '01/04/2005'
    })
    },{
    header: "Stundas",
    width: 20,
    sortable: true,
    dataIndex: 'hours',
    summaryType:'sum',
    renderer : function(v){
    return v +' st';
    },
    editor: new Ext.form.NumberField({
    allowBlank: false,
    allowNegative: false,
    style: 'text-align:left'
    })
    },{
    header: "Likme",
    width: 20,
    sortable: true,
    renderer: function(v){
    return v +' Ls/h';
    },
    dataIndex: 'rate',
    summaryType:'average',
    editor: new Ext.form.NumberField({
    allowBlank: false,
    allowNegative: false,
    style: 'text-align:left'
    })
    },{
    id: 'cost',
    header: "Summa",
    width: 20,
    sortable: false,
    groupable: false,
    renderer: function(v, params, record){
    return (record.data.hours * record.data.rate) + ' Ls';
    },
    dataIndex: 'cost',
    summaryType:'totalCost',
    summaryRenderer: function(v){
    return v +' Ls';
    }
    }
    ],

    view: new Ext.grid.GroupingView({
    forceFit:true,
    showGroupName: false,
    enableNoGroups:false, // REQUIRED!
    hideGroupedColumn: true
    }),

    plugins: summary,

    frame:true,
    width: 800,
    height: 450,
    clicksToEdit: 2,
    collapsible: true,
    animCollapse: false,
    trackMouseOver: false,
    //enableColumnMove: false,
    title: 'Timetracker',
    iconCls: 'icon-grid',
    renderTo: document.body,
    selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
    //stripeRows: true,//applies css classname to alternate rows, defaults to false
    tbar: [{
    text: 'Pievienot uzdevumu',
    tooltip:'Jauna uzdevuma pievienošana',
    iconCls:'add',
    handler: addRecord
    },'-',{
    text:'Dzēst uzdevumu',
    tooltip:'Dzēst izvēlēto uzdevumu',
    iconCls:'remove',
    handler: handleDelete
    },'-',{
    text:'Noņemt grupēšanu',
    tooltip:'Atļaut rediģēt projektus tāskiem',
    iconCls:'option',
    handler: function() {
    if (ds.GroupField = 'project')
    ds.clearGrouping();
    else
    ds.groupBy('project');}
    }]
    });

    function addRecord() {
    var task = new Task({
    project: '',
    id: '',
    task: '',
    project: '...',
    date: (new Date()).clearTime(),
    hours: 1,
    newRecord:'yes',
    rate: 7.0
    });
    grid.stopEditing();
    ds.insert(0, task);
    grid.startEditing(0, 0);
    };

    function handleEdit(editEvent) {
    var gridField = editEvent.field;//determine what column is being edited
    updateDB(editEvent);//start the process to update the db with cell contents
    }

    function updateDB(oGrid_Event) {
    var isNewRecord = oGrid_Event.record.data.newRecord;
    Ext.Ajax.request({
    url: 'data.php',
    method: 'POST',
    params: { //these will be available via $_POST or $_REQUEST:
    task: "saveData",
    id: oGrid_Event.record.id,
    dataId: oGrid_Event.record.data.id,//for new records this corresponds to the default assigned in addRecord()
    newRecord: isNewRecord,
    //newTask: oGrid_Event.record.data.task,
    //newProject: oGrid_Event.record.data.project,
    //newDate: oGrid_Event.record.data.date,
    //newHours: oGrid_Event.record.data.hours,
    //newRate: oGrid_Event.record.data.rate,
    field: oGrid_Event.field,//the column name
    value: oGrid_Event.value,//the updated value
    //value: '23/11/2007'
    },//end params
    //the function to be called upon failure of the request
    failure:function(response,options){
    Ext.Msg.alert('Warning','Oops...');
    //ds.rejectChanges();//undo any changes
    },//end failure block
    success:function(response,options){
    if(isNewRecord == 'yes'){
    var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
    var newID = responseData.newID;//extract the ID provided by the server
    //Ext.Msg.alert('Success','Yeah...nnewID: '+newID);
    oGrid_Event.record.id = newID;
    oGrid_Event.record.set('newRecord','no');//reset the indicator since update succeeded
    oGrid_Event.record.set('id',newID);//assign the id to the record
    ds.commitChanges();//commit changes (removes the red triangle which indicates a 'dirty' field)
    } else {
    ds.commitChanges();//commit changes (removes the red triangle which indicates a 'dirty' field)
    }
    }//end success block
    }//end request config
    ); //end request
    }; //end updateDB

    function handleDelete() {
    var selectedKeys = grid.selModel.selections.keys; //returns array of selected rows ids only
    if(selectedKeys.length > 0) {
    Ext.Msg.confirm('Message','Do you really want to delete selection?', deleteRecord);
    } else {
    Ext.Msg.alert('Message','Please select at least one item to delete');
    }//end if/else block
    }; // end handleDelete

    function deleteRecord(btn) {
    if (btn=='yes') {
    var selectedRow = grid.getSelectionModel().getSelected();
    if(selectedRow){
    ds.remove(selectedRow);
    }
    Ext.Ajax.request( //alternative to Ext.form.FormPanel? or Ext.BasicForm.submit{
    url: 'data.php',
    params: {
    task: "deleteData",
    id: selectedRow.id,
    },
    callback: function (options, success, response) {
    if (success) {}
    else {
    Ext.Msg.alert('Sorry, please try again. [Q304]',response.responseText);
    }
    },
    failure:function(response,options){
    Ext.MessageBox.alert('Warning','Oops...');
    },
    success:function(response,options){
    ds.reload();
    }
    } //end Ajax request config
    );// end Ajax request initialization
    };//end if click 'yes' on button
    }; // end deleteRecord


    grid.on('afteredit', handleEdit);//give event name, handler (can use 'on' shorthand for addListener)

    });


  • I also need the week to begin on monday but couldn't find anything in the API doc about setting startDay for a DateField. I found this though:

    http://extjs.com/forum/showthread.php?t=13609

    The question has been asked before, with the same confusing answers:

    http://extjs.com/forum/showthread.php?t=4948


  • hmm, datepicker is not the datefield, is it?

    {
    header: "Datums",
    width: 25,
    sortable: true,
    dataIndex: 'date',
    summaryType:'max',
    renderer: Ext.util.Format.dateRenderer('d/m/Y'),
    editor: new Ext.form.DateField({
    format: 'd/m/Y',
    minValue: '01/04/2005',
    startDay: 1
    })
    }

    This does not work. API is about datapicker, but this is datefield.. how can i apply startDay in this case?


  • Since the date (which in the Store is a Date object) value is going into params, you'll likely need to coerce it to a string (in the expected format 'd/m/y') , much like your grids date renderer function does.


  • oh, yeah, thanks. forgot about that..

    var field = oGrid_Event.field;
    if (field == 'date')
    value = Ext.util.Format.date(oGrid_Event.value, 'd/m/Y')
    else
    value = oGrid_Event.value


  • do you know how to get datepicker to start week at monday, not sunday?


  • @banesto - If you ask what you mean, you will likely get a better answer. Your question specifically says 'datapicker'. Did you read the other thread and do what Jack recommended?


  • Please read the API doc - see the startDay config.


  • yeah, i mixed that up, because tool for picking dates sounds like datepicker :) anyways, Jack's advice did the trick! Thanks!







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about value not being passed to php , Please add it free.