Hybrid View

  1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    48
    Vote Rating
    0
    devol is on a distinguished road

      0  

    Default Example of inserting a new row into the grid

    Example of inserting a new row into the grid


    Could you give an example of how to have a user click a link and insert a new row into the grid? I assume you would just insert a row into the DataModel, which would then fire the rowupdated event, however I'm not sure how this will play into the editor and validation hooks, since the row will be "empty" until filled out.

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    I would recommend providing dummy data on new rows. To use my plant example on the editor page, I have a function defined like this on a test page I use:
    Code:
          addRow : function(){
                addIndex++;
                var rowIndex = dataModel.insertRow(0, null, [
                    'New Plant ' + addIndex,
                    'Nueva Plantus Maximus ' + addIndex,
                    'Sun or Shade',
                    0,
                    new Date(),
                    false                
                ]);
                grid.startEditing(rowIndex, 0);
            }
    addIndex is just a counter variable that makes it New Plant 1, New Plant 2, etc.

    I am inserting a new row at index 0 (first row), with an id of null (null means auto-generate), with the array of column data. This method is on the XMLDataModel. The DefaultDataModel also has insertRow(), but it doesn't have an id argument. The XMLDataModel will also keep the document in sync by adding a new node in the XMLDocument matching the newly created row. It does this by cloning the first row's node. If you have a complex XML document and the clone node doesn't work for you, the XMLDataModel has a method createNode() that can be overridden to create your own node.

    Then I call startEditing() to activate editing for the newly inserted row on the first cell (0).

    Hope that helps,

    Jack

Similar Threads

  1. DomHelper bug inserting before/after a table element.
    By Animal in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 6 Mar 2007, 2:39 AM
  2. Bug in DomHelper/Template - inserting table rows
    By jarrednicholls in forum Ext 1.x: Bugs
    Replies: 1
    Last Post: 8 Jan 2007, 10:21 AM

Thread Participants: 1