Announcement

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

    Add a record to a listgrid with out saving into DB the moment addData() is called.

    Hi Isomorphic

    I have a requirement where in i should add a record to a listgrid. It should not be saved to database the moment addData() method is called, to add a record. After adding a record user should be able to edit the cells and when i click "save" the newly added record should be saved to database along with other edited old records.

    My detailed use case:
    1. I have a listgrid. The first column of the listgrid has "+" symbol displayed in each cell.
    2. When i click on the "+" symbol, i should add a new record below this record.
    3. The newly added record should have "+" symbol displayed in the first cell, the second and third cell values should be same as the values displayed in the above record where i clicked the "+" symbol. And the rest of the cells are blank.
    4. I will edit rest of the cells and click on "Save" button to save the record. Now i should be able to insert the newly added record and update the old records if they are edited.
    5. I have called "listgrid.addData()" method to add a new record. But it is trying to connect to server, to insert the record into the database.
    6. If i remove the operationType="add" tag from my datasource then i get an error "OperationType add is not defined in datasource". This error is because i removed the tag.

    How i can achieve this. Please help.


    Thanks and regards
    Srividhya

    #2
    If you don't want the record immediately saved, don't call addData(), call listGrid.startEditingNew().

    By default, records will then be saved when the user exits the row editor. To prevent this, also set autoSaveEdits:false, and trigger saving manually by calling listGrid.saveAllEdits().

    Keep in mind, if you are adding a new record, the ListGrid is going to be calling addData() to add it when you ultimately call saveAllEdits(), because you are adding a new record and that's what addData() does. So you will ultimately want a working "add" operation on your DataSource to add records.

    Comment


      #3
      Hi,
      I am using listGrid.startEditingNew() to add a new record in the list grid,with some default values copied from the existing record,

      i use the following code:
      Code:
      click: function(){
      record=listSample.getSelectedRecord();
      var criteria = {
      	       Name:record.Name,
                          Desc:record.Desc
                         }		    
                         listSample.startEditingNew(criteria,false); 
      }
      I get a new record added below my existing records with the default values,
      Now i need to get the Name field value for the newly added record.
      since i am not saving the new record values to the database,i am not able to get the values for that record.

      Is there anyway to get the values of the record added by using listGrid.startEditingNew() before saving the values to the database.

      Thanks,
      Keerthi

      Comment


        #4
        Take a look at the various APIs on the ListGrid related to editValues, for example, getEditedRecord(). These allow you to access and manipulate edits made by the user which have not yet been stored.

        Comment


          #5
          Thanks for the reply.

          I tried using the listgrid.getEditedRecord().But I am not able to get this newly added record.It is returning only the existing records value if they are edited.But not for this newly added record.I am getting null value for this record.

          please let me know if there are any ways to do this .

          Comment


            #6
            Possibly you have not called it correctly - can you show your complete code?

            Comment


              #7
              I have written a function on cellclick of my list grid.

              I am checking if the user is clicking on Desc field ,then i am trying to get the name field for this record.
              This works fine for existing records.however if i am adding a new record using listgrid.startEditngNew() ,and then if i click on the desc field ,i am getting the record as null.
              Code:
              cellClick: function (record, rowNum, colNum) { 											
               if(this.getField(colNum).title =="Desc"){
                         var  name = new Object(); 
                          if(record!=null)    
                         	 name = record.Name;
                           else{
                  var newrecord = listSample.getEditedRecord();
                  alert(newrecord);
                            }
                         }
              }
              in case of newly added record ,i am getting the alert as undefined.

              I am not able to select that newly added record also,in case if it gets selected then i think i can use the listgrid.getSelectedRecord() method.

              Any pointers on what i should do to get the value , will be really helpful.

              Thanks,
              Keerthi

              Comment


                #8
                getEditedRecord() has a required parameter, the rowNum, which you have not passed.

                Comment

                Working...
                X