Let’s say we have a grid listing clerks, and we want to be able to assign a boss to a clerk (yes, my favorite setup). A traditional way to do this is by using a combobox listing available bosses as options. Netzke does it for you automatically when it detects a foreign key between the model’s attributes. However, sometimes we want to be in more control over how one-to-many associations are handled in Netzke grids and panels. This tutorial will show you how to configure the following:
- How each boss should be represented in the drop-down list. Will it be her first name or last name? Or maybe an arbitrary string that combines them both and eventually includes some extra info (such as the boss’ salary)?
- Scoping out bosses in the drop-down list. We may not want to list all the bosses in the drop-down list. How could we limit those to a specific department, for instance?
Update 1: This tutorial assumes Rails 2.3.x and Ruby 1.8.7.
This blogpost will focus on how Netzke lets you specify and configure a model’s (virtual) attributes mapped to columns (in grids) and fields (in forms). The way it was done before passed through several iterations of improvements, and finally I can say that I found an approach I’m currently happy with. It’s very flexible, but at the same time the resulting code is readable, concise, and simply looks very habitual. Which problems is it solving? 1) Imagine, you want to render some HTML code in a grid cell (a link, an icon, etc). You could easily declare a method right in the model and use it as a virtual attribute. But it totally doesn’t feel right to put this into your model, as it’s about presenting the data, not the data itself. 2) Besides, different widgets may need different “representational” attributes for the same model – how would we handle that? Mix them in, in some way, into the model all together? Doesn’t feel right either, especially if there are naming conflicts. 3) Also, different widgets may need to render the same attribute in a different way (e.g., with different formatting). Well, all this is now covered in Netzke. Read on.
Recent update to
Today I’m coming up with a light-weight tutorial, which will show how to extend a Netzke widget in order to add a custom
This post continues the series of the tutorials on building Netzke widgets – reusable pieces of code for a Rails/ExtJS application. It extends the slightly outdated 