Announcement

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

    Inserting a new row in grid above any row

    Hi Isomorphic Team,
    We are using the ismorphic version : 6.1-p20170930
    my current functionality uses SmartGWT + Spring Rest services.
    We are using Google chrome browser latest version.

    My application has a requirement to insert a new row above the selected row.
    I have written the below code to achieve the same:

    protected void insertAction() {
    GWT.log("insertAction " + getCanEdit());
    if (getCanEdit()) {
    if (getSelectedRecord() == null) {
    startEditingNew();
    } else { // add the row at the selected index
    final int index = getDataAsRecordList().indexOf(getSelectedRecord());
    setRecords(getRecords());
    Record record = new Record();
    getRecordList().addAt(record, index);

    startEditing(index);
    newRowIndex = index;

    }
    }
    }


    Above code adds the row into DB but on UI the row is not displayed..
    I need refresh the grid to see the newly inserted row.

    Could you please suggest.

    #2
    This approach would work if you either modify the set of records before calling setRecords() / setData(), or simply call redraw(). The former approach is more efficient.

    However, this approach won't work with a ListGrid with a DataSource - you will end up only working with the records that have been loaded so far, and breaking automatic cache synchronization. To handle this properly in the DataSource case, see the Grid Editing overview, specifically the Handling Unsaved Records sub-topic.

    Comment


      #3
      Hi Team. Thanks for the response. I've checked the section that you mentioned above. Tried updateCaches(dsResponse) but no success.
      I have a datasource grid. This is how my implementation looks like:

      ViewListGrid grid = new ViewListGrid(Params here);
      DataSource myDS = DataSource.get("MyDS");
      grid.setDataSource(myDS);

      Initialy the grid is drawn by a fetch call on server. Then the insertion logic goes is :
      void insertAction() {
      if (getCanEdit()) {
      if (getSelectedRecord() == null) {
      startEditingNew();
      } else { // add the row at the selected index
      final int index = getDataAsRecordList().indexOf(getSelectedRecord());
      setRecords(getRecords());
      Record record = new Record();
      getRecordList().addAt(record, index);

      startEditing(index);
      newRowIndex = index;

      }
      }
      }

      This works fine for startEditingNew() for adding records in the end. Sends server call, saves records and reflects the same on UI.

      For inserting data at a particular index this logic sends the call to server , successufuly saves the record in DB and sends the DS response back to client but the problem is that the new saved record is not reflected on UI. The row becomes blank as soon as we get the response. If I reload the grid then the record is visible according to the sorting.
      I tried to updateCaches on DS response , Manually refreshed the particular index record by refreshRow(rowNum) but no success. Can you suggest some resolution? Thanks in advance.


      Comment


        #4
        We covered this above:

        However, this approach won't work with a ListGrid with a DataSource - you will end up only working with the records that have been loaded so far, and breaking automatic cache synchronization. To handle this properly in the DataSource case, see the Grid Editing overview, specifically the Handling Unsaved Records sub-topic.
        Once you have replaced the automatically created ResultSet with a RecordList that you have edited, the cache will no longer be updated automatically. You have to either update the RecordList yourself, or use one of the other approaches we document.

        Comment


          #5
          @preeti_kanyal any success ?

          Comment

          Working...
          X