backbone.datagrid icon indicating copy to clipboard operation
backbone.datagrid copied to clipboard

actionClassName callback is not passed the corresponding model.

Open gtzoganis opened this issue 11 years ago • 2 comments

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?

gtzoganis avatar Mar 06 '13 14:03 gtzoganis

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!

loicfrering avatar Mar 06 '13 16:03 loicfrering

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

gtzoganis avatar Aug 10 '13 19:08 gtzoganis