Announcement

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

    When is dataArrived called?

    I have a master-details situation (grids). The master grid gets loaded automatically (autoFetchData = true). In its dataArrived() handler, I select the first record of the grid (this.selectSingleRecord(0)). And via the selectionChanged() handler, I load the details grid if state = true (meaning the record is selected and not deselected, right?).

    So far this worked quite well, but now I found out that after a record edit, the dataArrived() also fires (at least in my set up), so this selects the first (master) record (mostly not the one edited), and loads the details of that record. I worked around this problem by creating an editComplete() handler, selecting the edited record. But this leads to a double fetch on the details grid (first for the first selected master record (an indirect result of DataArrived()), second for the edited record (a direct result of selectionChanged()).

    So I have these two questions:
    1) Is this a good approach (using the right handlers)?
    2) Is there another way of keeping the record that's being edited selected after a save? (by the way, I use auto saves)

    #2
    In addition:

    When a record is edited an no change is made, the record remains selected and no selectionChanged() occurs. I want the same behavior when ENTER is clicked and the record gets saved.

    Comment


      #3
      DataArrived does not normally fire after a save - this may indicate that you are using invalideCache() or similar in this circumstance.

      EditComplete is a good place to deselect the saved record if you wantthat behavior.

      Comment


        #4
        I have tried o so many scenarios and somehow the whole behavior isn't as expected. I have eliminated as many properties as I can think off, but it looks like dataArrived() always occurs. I never call invalidateCache(), but sometimes I use grid.setData([]), but not even in this case.

        Is it really true that dataArrived only occurs after a fetch? I have difficulties giving a fullblown example, but let me try to give a short impression:

        A universal REST-data source for RubyOnRails:
        Code:
        isc.defineClass('UniversalDataSource', isc.RestDataSource);
        
        isc.UniversalDataSource.addProperties({
          dataFormat: 'json',
          operationBindings: [
            {operationType: 'fetch',  requestProperties: {httpMethod: 'GET'}},
            {operationType: 'add',    requestProperties: {httpMethod: 'POST'}},
            {operationType: 'update', requestProperties: {httpMethod: 'POST', params: {_method: 'PUT'}}},
            {operationType: 'remove', requestProperties: {httpMethod: 'POST', params: {_method: 'DELETE'}}}
          ]
        });
        
        isc.UniversalDataSource.addMethods({
          initWidget: function () {
            this.Super('initWidget', arguments);
          }
        });
        The individual data source:
        Code:
        dataSource = isc.UniversalDataSource.create({
              dataURL: 'restful_path.json',
              fields: [
                // ...
              ]
            });
        The universal grid:
        Code:
        // creates a list grid with default properties
        isc.defineClass('UniversalListGrid', isc.ListGrid);
        
        // instance properties (defaults)
        isc.UniversalListGrid.addProperties({
          alternateRecordStyles: true,
          canSort: false,
          editComplete: function (rowNumber, columnNumber, newValues, oldValues, editCompletionEvent) {
            this.selectSingleRecord(rowNumber);
          },
          emptyCellValue: ' ',
          headerSpanHeight: 20,
          height: '100%',
          hoverWidth: 250,
          leaveScrollbarGap: false,
          modalEditing: true,
          recordEditProperty: '_update',
          recordEnabledProperty: '_enabled',
          selectionType: 'single',
          showHeaderContextMenu: false
        });
        
        // instance methods
        isc.UniversalListGrid.addMethods({
          initWidget: function () {
            this.Super('initWidget', arguments);
          }
        });
        The individual list grid:
        Code:
        grid = isc.UniversalListGrid.create({
          autoFetchData: true,
          canEdit: true,
          dataArrived: function (startRow, endRow) {
            alert(startRow + ' - ' + endRow);
          },
          dataSource: dataSource,
          fields: [
            // ...
          ]
        });
        I start an edit either via double click or edit via grid.startEditing(rowNumber). When using a double click, changing the record and saving it, I see the alert generated in grid.dataArrived(). I think this is not correct, isn't it?
        Last edited by wallytax; 10 Feb 2010, 08:44.

        Comment


          #5
          In IE, you can use getStackTrace to get the current stack as a String which you can log, so you can see how your logic is actually being called.

          Comment


            #6
            Although I work on a Mac, I managed to check IE and the response was not that clear for me, so I more or less stripped the whole application to a basic grid. ListGrid.dataArrived() occurs after a fetch, update and delete, but not after an add. If this is correct behavior I won't bother in trying to find out why that is.

            I still need to have a certain interaction with the user that I think should be simple, but unfortunately it isn't.

            Is there a good master-details example around that uses a foreign key kind of thing? I didn't use that so far, but I know SmartClient has something with foreign keys.

            Comment


              #7
              The Showcase Application shows a master-detail interaction.

              Your question has become quite vague and it's no longer clear what you're trying to solve.. to reselect a row after changes have been saved, use editComplete and previously indicated.

              Comment


                #8
                First, the editComplete works!
                Code:
                  editComplete: function (rowNumber, columnNumber, newValues, oldValues, editCompletionEvent) {
                    this.selectSingleRecord(rowNumber);
                  },
                As described, in my master my initial goal was to start with the first row of the grid selected, that's why I used dataArrived(). To load the details, I decided to use selectionChanged(). But then after an update or delete, dataArrived() gets called again, selecting the first record again, performing the load of the details (via selectionChanged) and then selected the last edited record (via editComplete). This means two fetches of details instead of one.

                I started with using recordClick() to load details, but this was difficult in combination with a double click event to edit records.

                Comment


                  #9
                  But... you could just detect whether the same record was selected, right?

                  Comment


                    #10
                    Not sure what you mean, but then I have to track which record was last selected or something? I went along that path already, keeping track of the last selected record and that meant a lot of extra code and was not satisfying either.

                    The example application is nice, but I'm not fully through it yet. One thing I did notice was the use of "isDSResponse: true" and "invalidateCache: false" in its response. Are there important?

                    Comment


                      #11
                      You must have some function that causes details for a given record to be loaded. In that function, check if the record is the same and don't reload if it's the same. Very simple, very little code, we use this technique all the time.

                      Comment


                        #12
                        A new day, new opportunities! Thanks a lot for the tips. But continuing on this approach, I try to create a universal grid, with this event:

                        Code:
                        editComplete: function (rowNumber, columnNumber, newValues, oldValues, editCompletionEvent) {
                          this.selectSingleRecord(rowNumber);
                        },
                        In the grid itself I load the details when a recordClick occurs. There I have this kind of code.

                        Code:
                        masterGrid = isc.UniversalListGrid.create({
                          _index: -1,
                          _record: null,
                          dataSource: masterDataSource,
                          recordClick: function (viewer, record, recordNumber, field, fieldNumber, value, rawValue) {
                            this.loadDetails(record);
                          },
                          loadDetails: function (record) {
                            var record = record || this.getSelectedRecord();
                            if (record != this._record) {
                              // START GRID SPECIFIC CODE
                              detailsGrid.setData([]);
                              if (record) {
                                detailsGrid.fetchData({filter_master_id: record.id});
                              }
                              // END GRID SPECIFIC CODE
                              this._record = record;
                              this._index = (record == null) ? -1 : this.getRecordIndex(record);
                            }
                          }
                        });
                        It would be nice that only the grid specific code could be placed in a function and that the universal grid does the rest of the loadDetails() method functionality. In the general editComplete I would like to perform this code as well.

                        But okay, I realize I can't ask you to program everything here, but in a way it would be nice if this kind of general master-details functionality could be shown in an example. It's almost there in the complete application, but in my honest opinion not clear enough.
                        Last edited by wallytax; 10 Feb 2010, 23:35.

                        Comment


                          #13
                          I'm getting there, so you could consider this question answered. I consider showing a clear version of my solution if it is appreciated.
                          Last edited by wallytax; 11 Feb 2010, 04:15.

                          Comment

                          Working...
                          X