Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Null pointer reference when #675

Open
pietersv opened this issue Jul 31, 2018 · 0 comments
Open

Null pointer reference when #675

pietersv opened this issue Jul 31, 2018 · 0 comments

Comments

@pietersv
Copy link

issue

In 0.38, when clicking a column header to sort I got this error:

    backgrid.js:2489 Uncaught TypeError: Cannot read property 'row' of undefined
    at backgrid.js:2489

solution

The issue appears to be in the method refresh which refers to this in a different scope. It's resolvable by keeping a reference to this in the method and referring to that inside the loop. The following method can be patched in:

  Backgrid.Body.prototype.refresh =function () {
    for (var i = 0; i < this.rows.length; i++) {
      this.rows[i].remove();
    }
    var self = this;   // NEW
    this.rows = this.collection.map(function (model) {
      var row = new self.row({                 // CHANGE `this` TO `self`
        columns: self.columns,                 // CHANGE `this` TO `self`
        model: model
      });

      return row;
    }, this);
    this._unshiftEmptyRowMayBe();
    this.render();
    this.collection.trigger("backgrid:refresh", this);
    return this;
  }
```### 
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant