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

Null pointer reference when  #675

Description

@protobi-pieter

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;
  }
```### 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions