Message-ID: <1476467545.375752.1710817908587.JavaMail.root@confluence-doc2-production> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_375751_994350730.1710817908581" ------=_Part_375751_994350730.1710817908581 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Table of contents
This Helper is used to generate a table of elements. The elements can be= long to ObjectModel-type objects, but they do not have to. Example: client = list, order status list.
Fields inside [brackets] are optional as per the HTML standard.
Value=
s between {curly braces} list the possible values for this field.
$this-&g= t;fields_list =3D array( 'country' =3D> array( // First column. 'title' =3D> $this->l('Country'), // Column name. 'width' =3D> 100, // Column width. At= least one field should be set to 'auto' in order to grow with window size. ['align'] =3D> {'left', 'center', 'right'}, // Content position= inside the column (default 'left', optional). ['type'] =3D> {'select', 'bool', 'date', // Column format. 'datetime', 'decimal', 'float', 'percent',=20 'editable', 'price'},=20 ['list'] =3D> $this->countries_array, // For type =3D= =3D select only. Content for the select drop down filter list (optional). ['filter_key'] =3D> 'cl\!id_country'), // Define a custom = filter key to be used by the filter SQL request=20 // (optional, default us= es the array key name, i.e. 'country'). ['orderby'] =3D> {true, false}, // If true, list wi= ll be alphabetically ordered using this column values (optional, default fa= lse). ['search'] =3D> {true, false}, // If true, this co= lumn will have a search field (optional, default true). ['image'] =3D> 's', // If set, an image= will be displayed in this field located in the '/img' subfolder defined as= value here (optional). ['image_id'] =3D> 3, // If 'image' is se= t and if 'image_id' is set, it will be used as the image filename,=20 // else the record item = id will be used (optional) ['icon'] =3D> array( =09 // If set, an icon = will be displayed with icon key matching the field value.=20 0 =3D> 'disabled.gif', // Used in combinat= ion with type =3D=3D bool (optional). 1 =3D> 'enabled.gif', 'default' =3D> 'disabled.gif' ), ['active'] =3D> 'status', // If set, the fiel= d will be replaced by a clickable boolean switch for the item field (i.e. '= status').=20 // An icon will display = the current status. ['activeVisu'] =3D> 'new_window', // If set, the fiel= d will be replaced by an icon depending on the boolean value // of the field specifie= d (i.e. 'new_window') (optional). ['callback'] =3D> 'getOrderTotalUsingTaxCalculationMethod', // If se= t, the return value of the defined method call=20 =09=09=09=09=09=09=09=09=09=09=09=09=09=09=09 // will be used as the fiel= d content (optional). ['callback_object'] =3D> $cart, // If set in combin= ation with 'callback', the method will be called from the provided object= =20 // instead of the curren= t controller (optional). ['prefix'] =3D> '0x', // If set, it will = be displayed before the field value (optional). ['suffix'] =3D> 'kg', // If set, it will = be displayed after the field value (optional). ['currency'] =3D> {true, false}, // If set and type = =3D=3D price, the currency displayed=20 =09=09=09=09=09=09=09=09=09=09=09=09 // will use the item currency and no= t the default currency (optional). ['maxlength'] =3D> 90, // If set, the fiel= d value will be truncated if it has more characters than the numeric value = set (optional). ['position'] =3D> 'position', // If set to positi= on, the field will display arrows =09=09=09=09=09=09=09=09=09=09=09=09 // and be drag and droppable, which = will update position in db (optional). ['tmpTableFilter'] =3D> {true, false}, // If set to true, = the WHERE clause used to filter results=20 =09=09=09=09=09=09=09=09=09=09=09=09 // will use the $_tmpTableFilter var= iable (optional, default false). ['havingFilter'] =3D> {true, false}, // If set to true, = the WHERE clause used to filter results=20 =09=09=09=09=09=09=09=09=09=09=09=09 // will use the $_filterHaving varia= ble (optional, default false). ['filter_type'] =3D> {'int', 'bool', 'decimal'}, // Specify the valu= e format when used in the filter where clause. // Useful when "filter_t= ype" is different from "type" (i.e. type =3D=3D select) (optional). ['color'] =3D> 'color', // If set, the fiel= d value will appear inside a colored element.=20 // The color used is the= "color" index of the record and is in HTML name or hexadecimal format (opt= ional). ['hint'] =3D> $this->l('This is the quantity available in the cur= rent shop/group.'), // The hint will appear on column name hover (optional)= . =09['ajax'] =3D> {true, false}=09=09=09=09=09=09// if the type is bool, = you use ajax ), 'another_field' =3D> array( // Second column. ... ), 'another_field' =3D> array( // Third column. ... ), );=20
Removing all the optional fields, this is how to build a basic HelperLis= t element:
private = function initList() { $this->fields_list =3D array( 'id_category' =3D> array( 'title' =3D> $this->l('Id'), 'width' =3D> 140, 'type' =3D> 'text', ), 'name' =3D> array( 'title' =3D> $this->l('Name'), 'width' =3D> 140, 'type' =3D> 'text', ), ); $helper =3D new HelperList(); =20 $helper->shopLinkType =3D ''; =20 $helper->simple_header =3D true; =20 // Actions to be displayed in the "Actions" column $helper->actions =3D array('edit', 'delete', 'view'); =20 $helper->identifier =3D 'id_category'; $helper->show_toolbar =3D true; $helper->title =3D 'HelperList'; $helper->table =3D $this->name.'_categories'; =20 $helper->token =3D Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex =3D AdminController::$currentIndex.'&confi= gure=3D'.$this->name; return $helper; }=20
This specific code generates this list:
By default, the list's header simply displays the name of each column.= p>
In order to make the column sortable and searchable, you only have to di= sable one option:
$helper-= >simple_header =3D false;=20
By disabling the simple_header
option, the list displays a =
more complex header:
The above example directly builds a table with an action column, which c= omprises three actions: edit, delete, view.
$helper-= >actions =3D array('edit', 'delete', 'view');=20
Note that they will not work out of the box: while the action icons are = there and can be clicked, nothing will happen when the user clicks until yo= u have assigned proper code to these actions.
You can define a "Details" action (or "+" action) in each row of a list.= This action is useful if you want to show other information about the row = (for example, the details of a sum).
This action is represented by a "+" if the details is shown and by a "-"= if the details is hidden. The content is obtained through an Ajax request.=
There are two possible ways to displays:
To add the "Details" action, use the following function in the target Ad= minController:
$this-&g= t;addRowAction('details');=20
Ajax requests must be generated by the ajaxProcess()
me=
thod in your AdminController.
Only one element is sent to the request: the table row's id=
code>. You can get it by using:
(int)Too= ls::getValue('id');=20
This id
is defined either in the $identifie=
r
class attribute, or by the table name ($table
attribu=
te), prefixed by "id_
".
This function must display the result in JSON format.
The expected JSON format:
{ use_parent_structure: true, // Optional. data: // Here is the SQL result. [ {field_name: 'value'} ], fields_display: // $fieldsDisplay attribute for the AdminCon= troller. }=20
Sample Ajax request code:
public f= unction ajaxProcess() { $query =3D 'SELECT * FROM mytable'; echo Tools::jsonEncode(array( 'data'=3D> Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query), 'fields_display' =3D> $this->fieldsDisplay )); die(); }=20
The expected JSON format:
{ use_parent_structure: false, data: '<p>My HTML content</p>' }=20