Announcement

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

    Correct way to dynamically update listgrid?

    After a user has entered a value into a cell in a listgrid I want to lookup information related to that field and prefill cells on that row of the grid. I have tried getting the record and modifying that but it doesn't update the visual display of the cell until you leave the row. So what is the correct method to dynamically edit cells?

    Code:
    ListGridField pnumField = new ListGridField("pnum","Policy Number",90); 
    pnumField.addEditorExitHandler(new EditorExitHandler() {
        	
        public void onEditorExit(EditorExitEvent event) {
                    ListGridRecord record = filingGrid.getRecord(0); //0 during test
                    record.setAttribute("transDate", "xxx"); //try updating another cell
             	}                	 
         });

    #2
    You are real close. Try grid method setEditValue.

    Comment


      #3
      Is this exposed in SmartGWT? It would be quite helpful if it were ;)

      Comment


        #4
        It's in SVN but not in the beta build or the currently posted JavaDoc.

        Comment


          #5
          Note also that you can directly update the dataset as you've shown, so long as you call refreshCell() after doing so.

          The difference between direct modification and setEditValue() is that setEditValue() causes the value to be treated as though the user had entered the value and it needs to be saved, whereas direct modification of the data is analogous to the data being changed on the server.

          Comment


            #6
            Thanks for your assistance.

            refreshCell() does the trick just fine. Question though - will the size of the grid and number of data elements have an effect on the performance of the refresh on a single cell or will it remain relatively constant?

            Comment


              #7
              Differs by browser, size of grid and other factors. In the worst case (IE) it makes more sense to just redraw() if you are refreshing more than a handful of cells.

              Comment


                #8
                Hi,

                I need to update one ListGrid after an edit in a second. The edit in the second affects a value in the first, so I want to make a "surgical" update, rather than refresh the whole thing.

                From reading several posts, I have cobbled together code that works the way I want.

                But I have some questions, now that I have a better understanding of what's going on behind the scenes. I also want to make sure this is a valid way to do it, before I start implementing this all over my code.

                Here's the editComplete event code of the second ListGrid (a list of issues of a particular magazine selected from the first ListGrid):

                Code:
                editComplete: function(rowNum, colNum, newValues, oldValues, editCompletionEvent, dsResponse) {
                		
                    // Get the magazine id from the response
                    // can possibly get this from new or old values arrays?
                    var magazine_id = dsResponse.data[0].issue_mag_id;
                
                    // Update magazine row, since the number of active issues may have changed
                    // First, fetch the updated magazine now (using the mag id as filter)
                    // Then, in the callback, update the magazine ListGrid
                    magazineRestDS.fetchData(
                        {mag_id: magazine_id},
                        function (dsResponse, data) {
                
                            // Get the new number of current issues
                            var active_issues = data[0].mag_active_issues;
                
                            // Retrieve the record index of this data in the magazine ListGrid
                            var matchingRow = magazineList.getRecordIndex(data[0]);
                
                            // matchingRecord is a pointer to row in magazine ListGrid data
                            var matchingRecord = magazineList.getRecord(matchingRow);
                
                            // Set the value of the column
                            matchingRecord.mag_active_issues = active_issues;
                
                            // Set the column number to update
                            var columnNumber = 3;
                
                            // Refresh the cell
                            magazineList.refreshCell(matchingRow, columnNumber);
                
                        }
                    );
                }

                1. Rather than use the optional dsResponse parameter of the editComplete callback, I assume I can use the oldValues array to get at the primary key field I want from the first ListGrid? The user does not have the ability to change it, so it should still be valid.


                2. I am using 6 lines of code in the fetchData callback. Is there a better way to accomplish this?


                3. How do I get the column number for a given field name? I am worried that if I add a column to the ListGrid, it will break my code. (Since I am hard-coding the column number).


                4. Before I wrote all this, I thought there'd be a simple method I could call, like ListGrid.Refresh(primaryKey, colNum), which would do all this. Would that be a valid wish list item?



                Thanks, and I hope everyone's doing well over there at Isomorphic -- I've been away for a while.

                Mike

                Comment


                  #9
                  1. either works

                  2. you could shorten it, but the helper you're asking for is what would make a large difference

                  3. getFieldNum(String fieldName)

                  4. Sure

                  Comment


                    #10
                    Should mention, in most cases the ResultSet "cache sync" behavior captures this kind of thing already - this approach is only for the rarer case of needing to manually update data because for whatever reason the change would not be detected by cache sync.

                    Comment


                      #11
                      Thanks for the feedback. Can you elaborate a bit on that last post?

                      I'm using a REST datasource - PHP on the back end, to MySQL server. How would I adjust a property of ResultSet, since I normally just bind ListGrids to DataSources?

                      Something like ListGrid.ResultSet.disableCacheSync = false ?


                      More generally...

                      Let's say a field value changes in my database. Are you saying there's a way for that to automatically "bubble up" to the ListGrid? Could I force it to happen, rather than wait for a timer of some sort?

                      That would be nice.

                      Mike

                      Comment

                      Working...
                      X