Jump to content

Grouping attributes into two columns: Difference between revisions

From NusaATK
No edit summary
 
No edit summary
Line 1: Line 1:
{{howto|easy|Jorge Garifuna <info at garidigital.com>}}
{{howto|easy|Jorge Garifuna <info at garidigital.com>}}
{{unstable}}


== Requirements ==
== Requirements ==

Revision as of 22:57, 28 August 2008

ATK Howto: Grouping attributes into two columns

Complexity: easy
Author: Jorge Garifuna <info at garidigital.com>

List of other Howto's

Note: The below is documentation for a feature that has not been stabilized. Please be aware that the API may change.

Requirements

ATK 6.2+

Summary

As of the ATK 6.2 nightly after July 29, 2008, there is a new way to add attributes into two columns. This howto walks you through the process.

I would like to commend [Rik http://forum.achievo.org/forum/viewtopic.php?t=10341&highlight=column] for bringing this great contribution to the ATK community.

Procedures

By default attributes are position on one single column in ATK. To position attributes on the right column you will need to call the following new method within your node:

    $this->setColumnAttribs($attributes=array())

This method will position any provided attributes to the right column of the node, to make a two column layout.

Assuming you had the following node:

        function employee()
        {
            $this->atkNode("employee", NF_ADD_LINK);//

            $this->add(new atkAttribute("id", AF_AUTOKEY));
            $this->add(new atkAttribute("name", AF_OBLIGATORY|AF_UNIQUE|AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("department_id","lesson3.department", AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("manager_id","lesson3.employee", AF_SEARCHABLE|AF_RELATION_AUTOCOMPLETE));

            $this->add(new atkDateAttribute("hiredate"));
            $this->add(new atkNumberAttribute("salary", AF_TOTAL));
            $this->add(new atkTextAttribute("notes", 0, AF_HIDE_LIST));

            $this->setOrder("name");
            $this->setIndex("name");
            $this->setTable("lesson3_employee");
        }

To display the attributes, name, salary and hiredate on the right column, you would need to apply the following to your node:

$this->setColumnAttribs(array("name","salary","hiredate"));

So your final code would look as follows:

        function employee()
        {
            $this->atkNode("employee", NF_ADD_LINK);//

            $this->add(new atkAttribute("id", AF_AUTOKEY));
            $this->add(new atkAttribute("name", AF_OBLIGATORY|AF_UNIQUE|AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("department_id","lesson3.department", AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("manager_id","lesson3.employee", AF_SEARCHABLE|AF_RELATION_AUTOCOMPLETE));

            $this->add(new atkDateAttribute("hiredate"));
            $this->add(new atkNumberAttribute("salary", AF_TOTAL));
            $this->add(new atkTextAttribute("notes", 0, AF_HIDE_LIST));

            $this->setColumnAttribs(array("name","salary","hiredate")); // places name, salary and hiredate on the right column
            $this->setOrder("name");
            $this->setIndex("name");
            $this->setTable("lesson3_employee");
        }

Below is an additional example with other options to display other fields on the right column:

        function employee()
        {
            $this->atkNode("employee", NF_ADD_LINK);//

            $this->add(new atkAttribute("id", AF_AUTOKEY));
            $this->add(new atkAttribute("name", AF_OBLIGATORY|AF_UNIQUE|AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("department_id","lesson3.department", AF_SEARCHABLE));
            $this->add(new atkManyToOneRelation("manager_id","lesson3.employee", AF_SEARCHABLE|AF_RELATION_AUTOCOMPLETE));

            $this->add(new atkDateAttribute("hiredate"));
            $this->add(new atkNumberAttribute("salary", AF_TOTAL));
            $this->add(new atkTextAttribute("notes", 0, AF_HIDE_LIST));

            // $this->setColumnAttribs(array("name","salary","hiredate")); // places name, salary and hiredate on the right column
            $this->setColumnAttribs(array("name","department_id")); // places name and department_id  on the right column
            // $this->setColumnAttribs(array("manager_id","hiredate","salary","notes")); // places manager_id, hiredate, salary and notes on the right column
            // $this->setColumnAttribs(array("salary","notes")); // place salary and notes on right column
            $this->setOrder("name");
            $this->setIndex("name");
            $this->setTable("lesson3_employee");
        }

Until next time,

[Jorge Garifuna http://www.GariDigital.com]