Skip to content

Instantly share code, notes, and snippets.

@melissathinkiq
Created October 9, 2018 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melissathinkiq/444b0f1a46d0572110c031090eef2aa9 to your computer and use it in GitHub Desktop.
Save melissathinkiq/444b0f1a46d0572110c031090eef2aa9 to your computer and use it in GitHub Desktop.
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/config.php';
$grid = new TiqGrid\TiqGrid(new TiqConfig);
// set few params
$opts["caption"] = "Tags";
// enable inline editing
$opts["cellEdit"] = true;
$opts["toolbar"] = "top";
$grid->set_options($opts);
// set database table for CRUD operations
$grid->table = "model.tags";
$grid->table_name = "tags";
$grid->select_command = "select id, relative_name, data_type, measurement_unit_id, description, historized from model.tags";
// show filtering of columns
$actions["autofilter"] = true;
$grid->set_actions($actions);
$cols = array();
$col = array();
$col["name"] = "id";
//$col['editable'] = false;
$col["hidden"] = true;
// pushes $col array to $cols array
$cols[] = $col;
$col = array();
$col["name"] = 'relative_name';
$col["editable"] = false;
$col["edittype"] = "text";
$col['title'] = "Name";
$cols[] = $col;
$col = array();
$col["name"] = 'display_name';
$col["edittype"] = "text";
$col['title'] = "Display Name";
$cols[] = $col;
$col = array();
$col["name"] = 'data_type';
$col["title"] = "Type";
$col["editable"] = false;
$col["edittype"] = "select";
$str = $grid->get_dropdown_values("SELECT unnest(enum_range(NULL::model.scalar_type_enum)) as k, unnest(enum_range(NULL::model.scalar_type_enum)) as v;");
$col["editoptions"] = array("value"=>$str);
$col["formatter"] = "select";
$cols[] = $col;
$col = array();
$col["name"] = "measurement_unit_id";
$col["editable"] = false;
$col["edittype"] = "select";
$col["title"] = "Units";
$str = $grid->get_dropdown_values("select id as k, display_name as v from model.measurement_units");
$col["editoptions"] = array("value"=>"NULL:;".$str);
$col["formatter"] = "select";
$cols[] = $col;
$col = array();
$col["name"] = "description";
$col["title"] = "Description";
$col["edittype"] = "textarea";
$col["editoptions"] = array("cols"=>35);
$cols[] = $col;
$col = array();
$col["name"] = "historized";
$col["title"] = "Historized";
//$col["editable"] = true;
$col['editoptions'] = array("value"=>"t:f");
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
// enables inline selection
$col["formatoptions"]["disabled"] = false;
$col["search"] = false;
$cols[] = $col;
$col = array();
$col["name"] = "Action";
$col["title"] = "act";
$col["width"] = 50;
$cols[] = $col;
$grid->set_columns($cols, true);
// render grid
$out = $grid->render($grid->table_name);
// display grid
$grid->displayGrid();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment