0

I try to use Backgrid.js. I have some grid (I just take server-mode example).

This library successfully built a grid for me. But I want map some cells to their equivalent. For example, I have "region_id" column. I want map region_id -> region_name. To complete this task, I subscribed to the event backgrid:rendered.

var grid = new Backgrid.Grid({
  /////

  collection: issues
});

grid.on('backgrid:rendered', function(g) { 
    $('tr').each(function (i, row) {

        var $row = $(row);

        console.log("Q");
    });
});

But I get a fail. There is no iterating over rows of my table. But these rows exist in table. What is the problem?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Denis
  • 3,595
  • 12
  • 52
  • 86
  • I created a small jsfiddle [here](http://jsfiddle.net/dethariel/gtt68z6d/). Can you please edit it so that the error is reproduced? Because currently I see the event being fired. – Dethariel Oct 27 '14 at 14:36

2 Answers2

0

Verify that both of the following is true:

  • you make a call to grid.render() method
  • issues variable refers to non-empty collection at the time of rendering
AndreiM
  • 4,406
  • 2
  • 18
  • 20
  • Both of these statements are true. The process of render is successful. Anyway, I solved my problem, using some workaround. – Denis Oct 27 '14 at 18:43
0

Unfortunately Backgrid fires the rendered event before the header, footer and the table itself are actually on the screen. So when your event gets triggered there are no rows in DOM yet. I solved my problem by calling my code after the grid.render().$el statement. After this table should be in DOM. At least header row was and that was all I needed.

I am stuck with old version of Backgrid 0.2.6. So bare in mind that my answer is from that perspective.

SimpleApp
  • 506
  • 4
  • 17