Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend smart-tables using custom directives #12

Closed
ojhughes opened this issue Jun 11, 2013 · 8 comments
Closed

How to extend smart-tables using custom directives #12

ojhughes opened this issue Jun 11, 2013 · 8 comments
Labels

Comments

@ojhughes
Copy link

Hello,

Thanks for your brilliant work. Could you provide a simple example of how to extend smart tables with a custom directive that access the API.

Thank you

@lorenzofox3
Copy link
Owner

Hello,
I don' know what you exactly mean by "extend". But any directive inside the smart-table directive can access the table API, it means :
-the built in directives that you can modify if you want (in Directives.js)
-any directive you associate to a cell template (using cellTemplateUrl property for example)
If you want a running example, you can go on the demo site.

Please note on the custom.js tab

  1. the require: '^smartTable' which means that the directive expect to find in its parent element the directive smartTable (
  2. the link function has a parameter ctrl wich is a reference to the table controller.

for more information about directive controller you can see the documentation

cheers,

Laurent

@ojhughes
Copy link
Author

Thanks, when I add a new directive to Directives.js with require: ^smartTable i get an error saying cant find smartTable controller

@lorenzofox3
Copy link
Owner

because your directive must have a parent elment in the markup wich has the 'smart-table' directive.

So it must be either one the directives you see in the table template, or one you will insert thanks to the cellTemplateUrl of your column config.

I suggest you watch [https://github.com/lorenzofox3/Smart-Table/blob/master/smart-table-module/partials/smartTable.html](this video), this explains what is a directive controller

Laurent

@ojhughes
Copy link
Author

Ah I understand now, thanks. Apologies I am very new to angular and still getting my head around directives.

@lorenzofox3
Copy link
Owner

no problem

@morgs32
Copy link

morgs32 commented Sep 18, 2013

Hi @lorenzofox3 I'd love to access the ctrl in the smartTableDataCell directive (which I'm trying to customize). But it comes up undefined. Probably an obvious thing I don't understand??
Thanks.

@lorenzofox3
Copy link
Owner

Hi,
As mentioned on the developer guide, you have to ask for it in your directive using the require property :

return {
                require: '^smartTable',
                link: function (scope, element, attr, ctrl) { 
                }
};

Laurent

@morgs32
Copy link

morgs32 commented Sep 18, 2013

Ahh. Thanks a ton. I'm getting a kick out of forking your project. Learning a lot from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants