kd12
kd12

Reputation: 1351

Backgrid.js with Backbone

I am using Backgrid for table structure. Now, I have to add action column having edit, view, delete buttons with column Header 'Actions'. I don't get how to do it using Backgrid. As we provided one column with one cell so how can I merge more than one cell under one column. Any idea?

Upvotes: 2

Views: 1167

Answers (2)

vassiliskrikonis
vassiliskrikonis

Reputation: 596

Just to add to the accepted answer, while extending the Backgrid.Cell class, it is very important to return this inside the render() function.

Backgrid default Row class/object uses cells like this:

render: function () {    
  ...
  fragment.appendChild(this.cells[i].render().el);
  ...
}

It expects render() to be chainable and return the object itself.

So... Don't forget to return this;

Upvotes: 0

Joni H.
Joni H.

Reputation: 166

This question is a bit old, so I am not sure if you found an answer. I am doing something very similar and found that you can extend the Backgrid cell when creating your columns. Hope this helps!

var columns = [
    {
        OTHER COLUMNS GO HERE
    },
    {
        name: 'actions',
        label: 'Actions',
        editable: false,
        sortable: false,
        cell: Backgrid.Cell.extend({
            template: _.template(" TEMPLATE OR HTML GOES HERE "),

            render: function () {
                this.$el.html(this.template());
                return this;
            }
       })
    }
]

EDIT: I just added the sortable option, after realizing that sortable defaults to true. You probably do not want to sort on the actions column. :)

Upvotes: 1

Related Questions