Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: roweditor after adding

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default roweditor after adding

    Hi, i'm not sure if this is a bug or an error in my code.

    Once i've added an item to a grid using the roweditor I am able to edit and remove it, but this does not call the appropriate php files. The update actual adds the item again with the changes and the remove does remove the item from the grid but the store does not call the delete php file.

    If I refresh the grid or do actions on other items they work perfectly, its just some strange behavior after adding.

    I've removed some code from around the grid, just a function called to display its tab and the tab panel definitions.
    Code:
        // Define extended grid for use in Proxy attribute of grids.
        var contact_edit_editor = new Ext.ux.grid.RowEditor({
            saveText: 'Update' // Changes text of the row edit button.
        });
        
        // List of Contacts associated to Company
        var nameContact_edit = new Ext.form.TextField();
        var valueContact_edit = new Ext.form.TextField();
            
        var contact_type_editgrid = new Ext.grid.GridPanel({
            title        : 'Contact Type',
            id            : 'contact_type_editgrid',
            plugins    : [contact_edit_editor], // Use grid extention defined above.
            view    : new Ext.grid.GroupingView({
                markDirty: false
            }),
            store        : contact_type_edit_store,
            columns     : [
                {header: "Id", dataIndex: 'idcontacttype',hidden:true},
                {header: "Contact Name", dataIndex: 'nameContact', editor: nameContact_edit},
                {header: "Contact Value", dataIndex: 'valueContact', editor: valueContact_edit}
            ],
            tbar: [{
                text: 'Add Contact Type',
                handler: function(){
                    var u = new contact_type_editgrid.store.recordType({
                        idcontacttype : '',
                        nameContact : '',
                        valueContact: ''
                    });
                    contact_edit_editor.stopEditing();
                    contact_type_edit_store.insert(0,u);
                    contact_type_editgrid.getView().refresh();
                    contact_edit_editor.startEditing(0);
                }
            },{
                text: 'Remove Contact Type',
                ref: '../removeBtn',
                disabled: true,
                handler: function(){
                    contact_edit_editor.stopEditing();
                    var s = contact_type_editgrid.getSelectionModel().getSelections();
                    for(var i = 0, r; r = s[i]; i++){
                        contact_type_edit_store.remove(r);
                    }
                }
        
            }]
        });
        
        contact_type_editgrid.getSelectionModel().on('selectionchange', function(sm){
            contact_type_editgrid.removeBtn.setDisabled(sm.getCount() < 1);
        });
    
       contact_type_edit_store.reload();
    Datastore code.
    I commented out the write listener as it was giving an error, maybe thats where the problem is?
    Code:
    // Contact Types
    
    // Proxy settings for built in CRUD functions.
    var contact_type_edit_proxy = new Ext.data.HttpProxy({
        api: {
            create  : './optionmanagement/assets/fnc/create_contact_types.php',
            read     : './optionmanagement/assets/fnc/get_contact_types.php',
            update    : './optionmanagement/assets/fnc/edit_contact_types.php',
            destroy : './optionmanagement/assets/fnc/destroy_contact_types.php'
        }
    });
    
    // Typical JsonReader.  Notice additional meta-data params for defining the core attributes of your json-response
    var contact_type_edit_reader = new Ext.data.JsonReader({
        totalProperty    : 'total',
        successProperty    : 'success',
        idProperty        : 'idcontacttype',
        root            : 'rows'
    }, [
        {name: 'idcontacttype'},
        {name: 'nameContact', allowBlank: false},
        {name: 'valueContact', allowBlank: false}
    ]);
    
    // The new DataWriter component.
    var contact_type_edit_writer = new Ext.data.JsonWriter({
        encode            : true,
        writeAllFields    : true
    });
    
    // Typical datastore of type grouping for roweditor grid.
    var contact_type_edit_store = new Ext.data.GroupingStore({
        proxy         : contact_type_edit_proxy, // Defined above.
        reader         : contact_type_edit_reader, // Defined above.
        writer         : contact_type_edit_writer, // Defined above.
        autoLoad    : true,
        autoSave     : true, // Automatically save when store is modified.
        listeners: {
            /*write : function(store, action, result, res, rs) {
                App.setAlert(res.success, res.message); // <-- show user-feedback for all write actions
            },*/
            exception : function(proxy, type, action, options, res, arg) {
                if (type === 'remote') {
                    Ext.Msg.show({
                        title: 'REMOTE EXCEPTION',
                        msg: res.message,
                        icon: Ext.MessageBox.ERROR,
                        buttons: Ext.Msg.OK
                    });
                }
            }
        }    
    });
    Thanks.

  2. #2
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default

    Any ideas from fresh eyes?

  3. #3
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default

    It's been 4 days since I posted this, over 50 views but yet not 1 response. I would of thought someone would know something about this, if the Ext support guys don't know I would still expect a response out of courtesy, even if its just that you've seen the issue. Has anyone else used these grids / datastore CRUD methods successfully? Examples of working programs would be a big help.

  4. #4
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    I'd suggest looking at one of the demos, or post working code someone can test out.

  5. #5
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default

    Quote Originally Posted by mjlecomte View Post
    I'd suggest looking at one of the demos, or post working code someone can test out.
    I used the demo's to create this code, most of its is copy and paste from the demo's hence my query about it being a bug or error on my part. I used http://www.extjs.com/deploy/ext-3.0.0/examples/writer/writer.html the datastore code and http://www.extjs.com/deploy/dev/examples/grid/row-editor.html for my roweditor grid.

  6. #6
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    If demo works stands to reason the error is in your code.

  7. #7
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default

    Quote Originally Posted by mjlecomte View Post
    If demo works stands to reason the error is in your code.
    Well its hard to tell as i'm using a row-editor but the DataWriter example uses a standard edit grid so mine is a combination of the two.

    I suspect its to do with the store side since its the store selecting if it should do add/update/delete but maybe there's some difference between edit grid and row-editor that is causign the issue? Maybe i'm missing a listener or something thats meant to end a Add process and make any subsequent processes on the new row a update/destroy process...

    I would of thought combination of row-editor and writer would be a common combination with pleanty of examples of them working together?

  8. #8
    Sencha User
    Join Date
    Jul 2009
    Posts
    36

    Default

    The other idea i've had on why it behaves wierd after a Add is the store not getting a response that the add was successful so is still expecting to add the row, thats also why it won't update/remove it as it doesn't have the id value from the db and trys to add the row again if you Update it.

    What does the store expect back from the PHP files when using the datastore Writer ?

  9. #9
    Sencha User
    Join Date
    Dec 2009
    Location
    Dallas, TX
    Posts
    20

    Default

    Hey Preston,
    Were you able to solve your problem, I am also facing the same issue can you please share what you have done to solve the issue.

    Thanks,

  10. #10
    Sencha User Monkee's Avatar
    Join Date
    Oct 2009
    Location
    Woking, UK
    Posts
    17

    Default Same here

    [SOLVED]

    I'm using an EditorGridPanel together with LockingGridView plugin.
    On "create" I always get an exception, altough the returned json code is well-formated.
    Still not found a solution.

    My problem was that the root value I used for the reader was different.

    Taking the example code of Preston:

    var contact_type_edit_reader = new Ext.data.JsonReader({
    totalProperty : 'total',
    successProperty : 'success',
    idProperty : 'idcontacttype',
    root : 'rows'
    }, [
    {name: 'idcontacttype'},
    {name: 'nameContact', allowBlank: false},
    {name: 'valueContact', allowBlank: false}
    ]);
    When you're using that custom value, be sure that the response type, after you insert a new record in your database, is following this pattern:
    {"success":true,"message":"Record added!","rows":{"id":"4b2f5226-1c38-448e-96ac-74dac0a80126","name":"New record"}}


    Because I was heavily inspired by the demos, I thought that the store/writer/reader were expecting the "data" object, but be careful to stick to that value you setup in the reader across all CRUD operations.
    Hope this helps!
    Last edited by Monkee; 21 Dec 2009 at 2:58 AM. Reason: solved

Page 1 of 2 12 LastLast

Posting Permissions

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