Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    updateData error

    Hi, i have a problem with updateData:
    in the code (listed below) there are an 'update' button, which makes an updateData operation on the dataSource 'contacts', the problem occurs when i add various records with the button 'add', and then i press the button 'update' (which detect all the modified records), producing incorrect display of the updated values in the listgrid. ¿ is there a problem in the code or i am missing something ?

    note: i most to use discardAllEdits() in the update button, because getAllEditRows.

    the code:






    isc.DataSource.create({
    ID:"contacts",
    dataFormat:"xml",
    recordXPath:"//Table",
    //dataURL:'http://192.168.1.9/Webservice2/service2.asmx/executeQuery?sSql=%20',
    fields:{
    au_id:{name:"au_id", primaryKey:true}, // primary key is necessary for removeData
    au_lname:{name:"au_lname"},
    au_fname:{name:"au_fname"},
    address:{name:"address"}
    },
    operationBindings:
    [
    {
    operationType:"fetch",
    dataFormat:"xml",
    recordXPath:"//Table",
    dataURL:"http://192.168.1.9/Webservice2/service2.asmx/executeQuery"
    },
    {
    operationType:"add",
    dataFormat:"xml",
    recordXPath:"//Table",
    dataURL:"http://192.168.1.9/Webservice2/service2.asmx/insert"
    },
    {
    operationType:"remove",
    dataFormat:"xml",
    recordXPath:"//Table",
    dataURL:"http://192.168.1.9/Webservice2/service2.asmx/remove"
    },
    {
    operationType:"update",
    dataFormat:"xml",
    recordXPath:"//Table",
    dataURL:"http://192.168.1.9/Webservice2/service2.asmx/update"
    }
    ]

    });



    isc.ListGrid.create({
    ID: "boundGrid",
    dataSource: "contacts",
    width: "100%",
    height:"80%",
    //autoFetchData: true
    canEdit:true,
    editByCell:true,
    headerHeight:15});



    isc.IButton.create({
    title: "fetch",
    width: 120,
    left: 100,
    top: 350,
    click: function()
    {
    boundGrid.data.invalidateCache();
    boundGrid.fetchData({sSql:'X'},null,{useHttpProxy:true}); //boundGrid.canEdit=false;
    //boundGrid.fetchData({sSql:' '},'boundGrid.canEdit=true');
    }
    });


    isc.IButton.create({
    title: "Add",
    width: 120,
    left: 250,
    top: 350,
    click: function ()
    {
    //boundGrid.data.invalidateCache();
    boundGrid.addData({au_id:'a',au_lname:'b',au_fname:'c',address:'d'},null,{useHttpProxy:true});

    }
    });




    isc.IButton.create({
    title: "remove selected",
    width: 120,
    left: 400,
    top: 350,
    click: function ()
    {
    if (boundGrid.getSelectedRecord())
    {
    //boundGrid.data.invalidateCache();
    boundGrid.removeData(boundGrid.getSelectedRecord(),null,{useHttpProxy:true});
    }

    }
    });



    isc.IButton.create({
    title: "update",
    width: 120,
    left: 550,
    top: 350,
    click: function ()
    {
    numrec=boundGrid.getAllEditRows();
    var rec;
    if (numrec.getLength()>0)
    {
    for (var i=0;i<numrec.getLength();i++)
    {
    rec=boundGrid.data.get(numrec[i]);
    boundGrid.updateData(rec,function(dsResponse,data, dsRequest)
    {
    var rowNum = boundGrid.data.indexOf(data[0]);
    if(rowNum >= 0) boundGrid.selectRecord(rowNum);
    },{useHttpProxy:true});

    }

    boundGrid.discardAllEdits();

    }

    }
    });

    boundGrid.fetchData({sSql:'%'},null,{useHttpProxy:true}); // only returns a blank record







    Thanks

    #2
    Hi Alex,

    I'd like to take a step back and try to get at how you want this application to behave.
    The current behavior is something like this:

    In your application you have a listGrid with dataSource set to 'contacts' - when you initially load the app you call 'fetchData()' on that listGrid, so all the contacts data in that dataSource should be fetched and displayed.

    When the user clicks the "Add" button, you call listGrid.addData().
    This will add a record to the dataSource for the listGrid.
    The new record should be saved to the server at this point, and displayed at the end of the grid.
    Note that you will not have any edit values outstanding at this point, so this.getAllEditRows() will return null.

    If the user edits a row at this point, the default behavior is for the edits to be saved to the server when the user stops editing the row (by pressing the "Enter" key, or starting to edit a different row in the listGrid).
    You can suppress that behavior via the "ListGrid.autoSaveEdits" property, if you want to do something else (like batch up the edits and submit them all at once).

    As currently implemented the update button uses a number of APIs - let me talk through these quickly:

    - it calls getAllEditRows()
    this method will return an array of row-numbers - one for each row that the user has edited that has not yet been saved to the server.
    [Note that when ListGrid.autoSaveEdits is true (the default), this method is unlikely to return multiple rows since they will get saved automatically when the user stops editing and moves to another row]

    - it calls 'data.get(...)' to get a pointer to each edited row's record.
    This method will return the record for each row-number passed in.
    Note that if there are outstanding edits, you will not see them in the object returned - this is looking at the record itself rather than the un-saved edit values.
    You can get a pointer to the unsaved, edited values via 'listGrid.getEditValues(rowNum)'.

    - it calls updateData()
    This is a method to update an existing row in the dataSource. You're passing in the record object retrieved from the 'data.get()' call above, so this would be expected to have no effect - you're updating the record with no changes to the edited values.

    - updateData() has a callback param to select the row after the save completes

    ---

    Some specific questions:

    1: When the user edits rows in this grid do you want them to save automatically to the server when the user moves to a new row?
    If not you may want to set 'autoSaveEdits' to false - this will give you the option to save edits only when the user clicks the "update" button.

    2: When the user hits the "Add" button, do you want the new record to be saved directly to the server, or just added as an editable row, waiting to be saved?
    Your current implementation looks ok for adding the record directly to the server.
    If you want to create an editable row in the grid (that has not yet been sent to the server), you can use setEditValues(...) to create a new set of edit values.

    3: What is the intended behavior when the user hits 'update'? It seems that if autoSaveEdits is true, this button is unnecessary, so I'm assuming that you want it to save all edited rows to the server.
    If so, rather than using 'updateData()', I think you want to use listGrid.saveEdits() to save each edited row, and pass in a callback to select the edited record when the save completes.

    This would mean your "update" button's click handler would look something like this:
    Code:
    function () {
        var editedRows = boundGrid.getAllEditRows();
        for (var i = 0; i < editedRows.length; i++) {
            var rowNum = editedRows[i]
            // Note: The second parameter for saveEdits is a callback to fire when the save completes.
            // It can be a function, or an expression (a string of script to evaluate).
            // The function will be fired with 3 parameters, the first of which is the rowNum
            // of the saved row -- also available as the keyword "rowNum" if a string of script
            // was passed in.
            boundGrid.saveEdits(null, "boundGrid.selectRecord(rowNum)", rowNum);
        }
    }
    Of course if the behavior I've described above is not what you want it may be easier to achieve your interface by having a client-only grid for the user to edit the data and then making explicit calls to the data-management methods on the DataSource when you want to update records, etc.

    I hope this is somewhat helpful.
    If you still can't get your application working how you want it to, let us know, along with as much detail as you can on how you expect the application to behave and we'll revisit this

    Thanks
    Isomorphic Software

    Comment


      #3
      Hi, first of all, thanks for your answer.
      the behavior that i try to get is save all the edited records in batch when the user press the update button (exactly like you show me in your code), i did not know that the listgrid will save the updated record automatically to the server when the user changes to another record, i most to say that your comments show me many things that were unknown for me.i'll try the code with the changes and will back if found an error.
      Thanks.

      Comment


        #4
        Hi, i prove the code but i find the following problem:

        using saveEdits in the 'update' button with autoSaveEdit:false (or automatic update when user change to another row in listgrid with autoSaveEdit:true). in both cases the web service is called only passing it (like parameters) the primary key field and the changed field, producing and error because the webservice function expects all the parameters.the question is: ¿ how can i pass all the parameters to the webservice when an update occurs?.

        Comment


          #5
          This question has been answered in this other thread.

          Comment

          Working...
          X