1

Hello guys I am using backgrid to render my table. I can't figure out how to add a element in the column. Can somebody tell me how can I do that.

1 Answers1

0

After see the docs/api here: http://backgridjs.com/ You can achieve that with somethings like :

// Since 0.3.0, you can listen to the `backgrid:next` to see if a cell
// movement was out of bound, if yes, you can insert a new row.

// A movement is only out of bound when the user was trying to go beyond
// the last row.
grid.collection.listenTo("backgrid:next", function (i, j, outOfBound) {
  // this will add a row using the collection's model too
  if (outOfBound) grid.collection.add({});
});

You can probably add a row/element with this code : grid.collection.add({});

EDIT

So Backgrid.js use Backbone.js to add a row with this method : insertRow( model, collection, options) (http://wyuenho.github.io/backgrid/api/index.html#!/api/Backgrid.Body)

When called directly, it accepts a model or an array of models and an option hash just like Backbone.Collection#add and delegates to it. Once the model is added, a new row is inserted into the body and automatically rendered.

Then we have :

var ships = new Backbone.Collection;

ships.on("add", function(ship) {
  alert("Ahoy " + ship.get("name") + "!");
});

ships.add([
  {name: "Flying Dutchman"},
  {name: "Black Pearl"}
]);

Hopes this help you ;)

Francois Borgies
  • 2,378
  • 31
  • 38
  • I do not want to add a column. I want to a element in a column –  Feb 25 '16 at 07:35
  • Yes an element in a column I call it a row. So add a row to add a element it's a good idea for me. Have you columns or just one ? – Francois Borgies Feb 25 '16 at 07:38
  • So If you want to add a element in column, you have to add a row with this element and an empty case for the other column like grid.collection.add({"element"," "}); – Francois Borgies Feb 25 '16 at 07:43
  • if it's not a problem can you please give me a small example that would be a great help –  Feb 25 '16 at 07:44