Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: CRUD example

  1. #1
    Sencha User bkraut's Avatar
    Join Date
    Nov 2007
    Location
    Maribor, Slovenia
    Posts
    403

    Default CRUD example

    Hi,

    I checked CRUD example and I allways get id assigned with 'ext-record-number'.

    Example:

    {"first":"tret","last":"tre","email":"fdg","id":"ext-record-1"}

    In my example id has Long type in database (autoincrement), so I get a runtime exception when submitting.

    How can I use CRUD store, if I want to assign id on the server side.

    I realy need this urgent.
    Best regards,

    Bojan

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

    Default

    If you have not specified an id, or configured the reader where to find the id, then your records will be created as phantom records with an autogenerated id. Your backend should create an id for a record submitted to server that way. The server would send back the "real" id and then the client side record id would be updated accordingly.

  3. #3
    Sencha User bkraut's Avatar
    Join Date
    Nov 2007
    Location
    Maribor, Slovenia
    Posts
    403

    Default

    I understand this. The case is following:

    When I create a new record (new row), this row should exist just in memory - this is a new record - id should be null. When I submit a row to the server (change line or click an Update button), then a record should be submitted to the server. On the server side I use gson, which can create an object directy from json in java. IfI do that now, I get a run time exception, as 'ext-record-1' can not be updated to Long. Anyway, I do not even want that anything is assigned to an id, as id is generated when I commit a session transaction on server.

    The problem is also, when I submit a new row - if I assign a new id on the server side, the client side (extjs grid) is not updated. Even if transaction on the server side fails I have a new record in the grid. I think this is not acceptable.

    I checked the whole example, but I don't find where an id that extjs creates is replaced with the id php gets from the session.

    Bojan

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

    Default

    If you're referring to the writer example, IIRC it is not a fully functional example, it just sends back a static id or something. It would be up to your serverside technology of choice to return an appropriate id to the client.

    Ext has always created some id for each record. It is the unique identifier to find the record. You can't have multiple records floating around with "id:null".

  5. #5
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    you could convert them while submitting your data back
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  6. #6

    Default

    Quote Originally Posted by mjlecomte View Post
    If you have not specified an id, or configured the reader where to find the id, then your records will be created as phantom records with an autogenerated id. Your backend should create an id for a record submitted to server that way. The server would send back the "real" id and then the client side record id would be updated accordingly.
    I'm trying to to that:

    I insert a new row via button with this handler:

    Code:
    handler : function(){
                            var conn = new Ext.data.Connection();
                            conn.request({
                                  url: 'url-to-manage-db-page.php',
                                  method: 'GET',
                                  params: {
                                        action: 'insert',
                                        table: 'ch_operatori',
                                        nome: 'Nuovo Operatore...'
                                  },
    All ok row is inserted in DB

    my on success:
    Code:
    success: function (resp, opt){
                                        
                                        var insert_id = Ext.util.JSON.decode(
                                            resp.responseText
                                        ).insert_id;  // <-- insert id returned as aspected
    
    
                                        
                                        // access the Record constructor through the grid's store
                                        var Operatore = gridOperatori.getStore().recordType;
                                        var o = new Operatore({
                                            id_utente:insert_id,   // <--- here my troubles, this update the id in data object not the phantom object id.... how to do ?that
                                            nome: 'Nuovo Operatore...',
                                            cognome: '',
                                            mail: '@asl1.liguria.it',
                                            telefono: '',
                                            fax: '',
                                            ambiti: '',
                                            ip_per_cookie: ''
                                        });
                                        
                                        gridOperatori.stopEditing();
                                        storeOperatori.insert(0, o);
                                        gridOperatori.startEditing(0, 0);
    The question is above in the code... How to update/change object id...

    I'm using it to manage the afteredit db update:

    Code:
    afteredit: function(e){
                            var conn = new Ext.data.Connection();
                            console.log(e.record);
                            conn.request({
                                    url: 'url-to-manage-db-page.php',
                                    method: 'GET',
                                    params: {
                                          action: 'update',
                                          table: 'ch_operatori',
                                          id: e.record.id,   //  <--- here
                                          field: e.field,
                                          value: e.value
                                    },
    Using e.recod.data.id... it's impossible cause in the afteredit event id is already changed... of course...

    Any suggestion?

    Regards

  7. #7
    Sencha User bkraut's Avatar
    Join Date
    Nov 2007
    Location
    Maribor, Slovenia
    Posts
    403

    Default

    The case is next:

    If I open a form I don't need to create a record on the server side yet. As I can close the form and record will never be stored in the batabase.

    If I ask a server to create a new record, the server will prepare all the necesary data for a new recrd, but still no id is mandatory as I can play with an object and discard it if necessary.

    If I would do a new invoice like this I would get problems - as I create an invoice with a number 100 and someone else creates an invoice with a number 101 a second later. If I discard my invoice I also have to delete my invoice and finaly I have a missing id in the database.

    So the explanation is simple. Extjs needs an unique record id, as all updates are performed on the basis of this id. If none is provided a default id is generated, which can be replaced on the server side if necesary (I don't like this idea, as it includes some parsing of the id string).

    Best regards,
    Bojan

  8. #8

    Default

    Quote Originally Posted by bkraut View Post
    The case is next:

    If I open a form I don't need to create a record on the server side yet. As I can close the form and record will never be stored in the batabase.

    If I ask a server to create a new record, the server will prepare all the necesary data for a new recrd, but still no id is mandatory as I can play with an object and discard it if necessary.

    If I would do a new invoice like this I would get problems - as I create an invoice with a number 100 and someone else creates an invoice with a number 101 a second later. If I discard my invoice I also have to delete my invoice and finaly I have a missing id in the database.

    So the explanation is simple. Extjs needs an unique record id, as all updates are performed on the basis of this id. If none is provided a default id is generated, which can be replaced on the server side if necesary (I don't like this idea, as it includes some parsing of the id string).
    Everything corrects but:

    I want just provide an id (a specific id) to Ext here:
    Code:
    success: function (resp, opt){
                                        
                                        var insert_id = Ext.util.JSON.decode(
                                            resp.responseText
                                        ).insert_id;
                                        
                                        // access the Record constructor through the grid's store
                                        var Operatore = gridOperatori.getStore().recordType;
                                        var o = new Operatore({
                                            id_utente:insert_id,   <-------- here
                                            nome: 'Nuovo Operatore...',
                                            cognome: '',
                                            mail: '@...',
                                            telefono: '',
                                            fax: '',
                                            ambiti: '',
                                            ip_per_cookie: ''
                                        });
                                        gridOperatori.stopEditing();
                                        //Inserisco la nuova riga nella griglia
                                        storeOperatori.insert(0, o);
    or replacing the auto generated with mine....
    But I don't know how?

    I'm setting up a grid that change information, add and remove items (operators)... Add a new operator in the grid with only it's id and then modify other data with "afteredit" method in ExtJs it's impossible?!?.. I don't think so....

    Regards
    Filippo

  9. #9

    Default

    Quote Originally Posted by bkraut View Post
    The case is next:

    If I open a form I don't need to create a record on the server side yet. As I can close the form and record will never be stored in the batabase.
    Sorry, I've read with no attention...

    In my case I insert a new record immediately because I want to use 'afteredit' event...

    But the problem is the same.. If I want to write all my record and then call an insert on a remote script I want be able to update the phantom id with the real id generated... or reject the data...

  10. #10
    Sencha User VinylFox's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD
    Posts
    1,501

    Default

    What is your store configured like? Are you specifying an 'id' or 'idProperty' of 'id_utente'?

    Typically when im inserting new records, I need to send a zero as the 'id', so I simply check the existing 'id' to see if it starts with 'ext' and change it to zero before I submit the data.

Page 1 of 3 123 LastLast

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
  •