loicfrering / backbone.datagrid

A powerful component, based on Backbone.View, that displays your Backbone collections in a dynamic datagrid table.
http://loicfrering.github.io/backbone.datagrid/
MIT License
55 stars 14 forks source link

actionClassName callback is not passed the corresponding model. #10

Open gtzoganis opened 11 years ago

gtzoganis commented 11 years ago

Hi,

Thanks for this component, it is very useful.

I have encountered a case that seems like a bug. In your documentation I read: "cellClassName (string|callback)

The class name of the cell (td or th). It can be a string or a callback which will be passed the model related to the current row. "

Since there is no specific documentation for an actionClassName that is defined for a view of type ActionCell, I tried to follow the above and assign a function to it that is passed the row model. That did not work.

I have fixed it by editing the source code of Backbone.Datagrid, and replacing the lines if (this.options.actionClassName) { a.addClass(this.options.actionClassName); } with if (this.options.actionClassName) { var actionClassName = this.options.actionClassName; if (_.isFunction(actionClassName)) { actionClassName = actionClassName(this.model); } a.addClass(actionClassName); }

It is working ok. I wonder if you think you can include it in a next release of Backbone.Datagrid?

loicfrering commented 11 years ago

Well there is indeed a difference between how are managed cellClassName (className for the <td>) and actionClassName (className for the <a>).

You're right, actionClassName should support receiving a callback function too so I'll add this to the next release. In the meantime feel free to open a Pull Request, I would be very pleased to merge it!

gtzoganis commented 11 years ago

pull request created. It is the first time I ever use git, so I hope I haven't done something silly.