AD

Ext2.0 code tracking: GridPanel only one line record, select the field events also triggered changes

Background:

Interface has two GridPanel, respectively, list the invoice cost of lists. More than the corresponding costs is a necessary verification.

Applications, select an invoice record, automatically loads the corresponding costs under the same business, and calculate the total cost amount. The total amount of the fees back to write an invoice write-off amount of the selected field.

When the invoice multiple rows, everything is normal. When the invoice is only one, the occurrence of infinite loop.

Commissioning: Initial debug found that if only one invoice, the charges removed himself finished loading, then load.

View Ext source code, found to be Ext2.0 a bug. After the Ext2.2 have been resolved.

Process:

1, write-back write-off the invoice amount, called the Record of the set method.

set : function(name, value){
        if(String(this.data[name]) == String(value)){
            return;
        }
        this.dirty = true;
        if(!this.modified){
            this.modified = {};
        }
        if(typeof this.modified[name] == 'undefined'){
            this.modified[name] = this.data[name];
        }
        this.data[name] = value;
        if(!this.editing && this.store){
            this.store.afterEdit(this);
        }
    }


2, Store of afterEdit methods, trigger update events

 // private
    afterEdit : function(record){
        if(this.modified.indexOf(record) == -1){
            this.modified.push(record);
        }
        this.fireEvent("update", this, record, Ext.data.Record.EDIT);// Trigger event, view related listener  , Guess the GridView or  GridPanel
    },


3, GridView monitor the store's update event, then trigger the onUpdate method.

The onUpdate refreshRow method is called directly.

Here, you can see the changes when the Record, GridView's approach is to insertRows then onRemove. Finally triggered rowupdated event. Had followed rowupdated event listener and found no abnormalities.

Because it is only a problem until a row, so it is necessary to judge sensitive to digital.

When only one Record, in the insertRows method, actually only refreshes. Not really deleted.

Next is to see what refresh methods?

// private
    initData : function(ds, cm){
        if(this.ds){
            // Omit  --
        }
        if(ds){
            ds.on("load", this.onLoad, this);
            ds.on("datachanged", this.onDataChange, this);
            ds.on("add", this.onAdd, this);
            ds.on("remove", this.onRemove, this);
            ds.on("update", this.onUpdate, this);
            ds.on("clear", this.onClear, this);
        }
        this.ds = ds;
       // Omit  ....
    },
// private
    onUpdate : function(ds, record){
        this.refreshRow(record);
    },
// private
    refreshRow : function(record){
        var ds = this.ds, index;
        if(typeof record == 'number'){
            index = record;
            record = ds.getAt(index);
        }else{
            index = ds.indexOf(record);
        }
        var cls = [];
        this.insertRows(ds, index, index, true);
        this.getRow(index).rowIndex = index;
        this.onRemove(ds, record, index+1, true);
        this.fireEvent("rowupdated", this, index, record);
    },
insertRows : function(dm, firstRow, lastRow, isUpdate){
        if(firstRow === 0 && lastRow == dm.getCount()-1){
            this.refresh();
        }else{
            if(!isUpdate){
                this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
            }
            var html = this.renderRows(firstRow, lastRow);
            var before = this.getRow(firstRow);
            if(before){
                Ext.DomHelper.insertHtml('beforeBegin', before, html);
            }else{
                Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
            }
            if(!isUpdate){
                this.fireEvent("rowsinserted", this, firstRow, lastRow);
                this.processRows(firstRow);
            }
        }
    }


4, GridView to refresh triggered the refresh event, then trigger Ext.grid.RowSelectionModel the onRefresh function.

Changes will be thrown directly select the event.

 onRefresh : function(){
        var ds = this.grid.store, index;
        var s = this.getSelections();
        this.clearSelections(true);
        for(var i = 0, len = s.length; i < len; i++){
            var r = s[i];
            if((index = ds.indexOfId(r.id)) != -1){
                this.selectRow(index, true);
            }
        }
        if(s.length != this.selections.getCount()){
            this.fireEvent("selectionchange", this);
        }
    }


Integrated with a code tracking. Step 3 of the GridView's insertRows method calls the refresh () is the cause of the problem lies. You override this method to solve this problem.

/**
 *  Fix Grid has only one data  , On the record when you call the set method  , Would cause a refresh/select event  
 *20101125.1 By  Simon
 */
Ext.grid.GridView.prototype.insertRows = function(dm, firstRow, lastRow, isUpdate) {
        if (!isUpdate && firstRow === 0 && lastRow >= dm.getCount() - 1) {// To determine whether only  update
                this.refresh();
        } else {
                if (!isUpdate) {
                        this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
                }
                var html = this.renderRows(firstRow, lastRow);
                var before = this.getRow(firstRow);
                if (before) {
                        Ext.DomHelper.insertHtml('beforeBegin', before, html);
                } else {
                        Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
                }
                if (!isUpdate) {
                        this.fireEvent("rowsinserted", this, firstRow, lastRow);
                        this.processRows(firstRow);
                }
        }
        this.syncFocusEl(firstRow);
};
标签: amp, source code, interface, string value, debug, occurrence, indexof, infinite loop
分类: Web
时间: 2010-11-26

相关文章

  1. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "7" (Concluded)

    http://www.blogjava.net/ilovezmh/archive/2009/01/12/251038.html Part VII Ext2.0 tree tabpanel gridpanel other ...
  2. Ext2.0 common grid, including (by. Delete. Change. Check. Exported excel)

    Here's the code for the grid expansion / ** * @ Auther huangfeng * @ Class Ext.ux.GridExtend * General grid * ...
  3. ext2.0 + struts2.1 + spring2.0 + jdbc framework

    Using the framework of the: ext2.0 + struts2.1 + spring2.0 + jdbc, personal accounts system
  4. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "1"

    http://www.blogjava.net/ilovezmh/archive/2008/12/26/248565.html The first part of the overall description The ...
  5. Entity Framework 5.0 Code First全面学习

    Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code First 时基于类定义自动 ...
  6. ext2.0 Upgrade ext3.1 Notes

    Recently in the project to upgrade the ext to ext3.1, a record of some of the problems: Question 1: ext3.x ver ...
  7. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "2"

    http://www.blogjava.net/ilovezmh/archive/2008/12/27/248570.html The second part velocity1.5 template engine Fi ...
  8. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "4"

    http://www.blogjava.net/ilovezmh/archive/2008/12/27/248681.html The fourth section for the database table stru ...
  9. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "5"

    http://www.blogjava.net/ilovezmh/archive/2008/12/28/248725.html Part V struts2 + spring2.5 + ibatis2 Integrati ...
  10. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "6"

    Part VI automatically generated additions and deletions to change search method, and added to the configuratio ...
  11. Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "3"

    http://www.blogjava.net/ilovezmh/archive/2008/12/27/248675.html The third part of the database used Hsqldb HSQ ...
  12. ext3.0 tabpanel nested gridpanel does not appear in the scroll bar

    Finally this thing buttoned up. Original gridview refresh this function also seems to cultivate enough ah grid ...
  13. EXT2.0 related problems in the store

    On the store loading problem: store the loading is asynchronous, it can not be sequential, if you want to load ...
  14. Baidu Google Search 1.0.0 version you pull on the line

    Baidu to write their own Google search tool, the current version of the lower room for improvement, presentati ...
  15. Validation on EXT2.0 of Ext.form.VTypes extension

    As the different needs, Ext.form.VTypes provides validation rules can not meet our requirements, but we can ex ...
  16. [Lucene3.0 the first glimpse of] the index file format (3): Field data [. Fdx /. Fdt /. Fnm]

    Note: The following article is a see http://lucene.apache.org/java/3_0_1/fileformats.html # Fields and practic ...
  17. tomcat5.0 deployment of engineering problems with the record 5.5

    1 tomcat 5.0 in Tomcat50 \ conf \ Catalina \ localhost \ test.xml in the configuration Project: <Context Do ...
  18. spring mvc 3.0 when using the annotation file how to select a different type of return

    For example, the top one with annotations and a Test2Controller TestController When inside the method returns ...
  19. Detailed AWK command (Daquan)

    What is awk? You may be familiar with UNIX, but you may be familiar with awk, it is not surprising, really, co ...